I was just lying in bed reading about keyboard layouts, as one does: https://en.wikipedia.org/wiki/Keyboard_layout?wprov=sfti1
This led me down a fascinating rathole. To start, what’s the name of the ( character? That’s right, it’s Open Parenthesis, not Left Parenthesis!
When I type Open Parenthesis on an Arabic keyboard, then Latin Capital Letter X, then Close Parenthesis, it looks like (X), of course—but what if I type it in Arabic? It looks like (X), even though the glyphs proceed right to left! The first character on the right, ), is the Open Parenthesis, then comes the Latin Capital Letter X, then the final Close Parenthesis, which looks like (.
I already knew this, of course. What I just learned (but not too late!) is that the ) key on Arabic keyboards types Open Parenthesis and the ( key types Close Parenthesis character, just as the . key on Arabic keyboards types the Arabic Full Stop character and the ؟ key types the Arabic Question Mark character. Simple!
But what if I’m using my Arabic keyboard to code in C? I first switch my computer’s “system language” to English, so that the . key types an ordinary Full Stop and the ؟ key types Question Mark, as God surely intended.
“But… but… but…”, you jammer, “but what if I want to use Arabic comments in my C code?” No problem! Just type the Arabic comments, and the amazing Unicode Bidirectional Algorithm (UBA) takes over, making your C code run LTR on your screen but your comments run RTL! Of course, the UBA isn’t perfect, so power users can fine-tune it with BiDi override characters, switching manually between LTR and RTL as “needed.”
“But isn’t that a security hole?” Yes, of course it is. Evil power users can use BiDi overrides to make /* look like it's at an EOL when it’s actually starting a block. Ruh-roh! And that’s why GCC and Clang warn you when they detect BiDi overrides in your code!
Tomorrow I’ll talk about how the compilers’ error messages will output jumbled snippets when they quote excerpts from your BiDi code. And don’t get me started on how Arabic characters shift their appearances depending on the surrounding characters, and how this affects the form of Arabic text once used on punch cards! But now it’s time to get out of bed!