this post was submitted on 11 Oct 2024
857 points (98.3% liked)

Programmer Humor

32715 readers
841 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

cross-posted from: https://lemmy.zip/post/24335357

you are viewing a single comment's thread
view the rest of the comments
[–] thevoidzero@lemmy.world 5 points 2 months ago (1 children)

I thought the most mode sane and modern language use the unicode block identification to determine something can be used in valid identifier or not. Like all the 'numeric' unicode characters can't be at the beginning of identifier similar to how it can't have '3var'.

So once your programming language supports unicode, it automatically will support any unicode language that has those particular blocks.

[–] NeatNit@discuss.tchncs.de 4 points 2 months ago (3 children)

Sanity is subjective here. There are reasons to disallow non-ASCII characters, for example to prevent identical-looking characters from causing sneaky bugs in the code, like this but unintentional: https://en.wikipedia.org/wiki/IDN_homograph_attack (and yes, don't you worry, this absolutely can happen unintentionally).

[–] toastal@lemmy.ml 8 points 2 months ago* (last edited 2 months ago) (1 children)

OCaml’s old m17n compiler plugin solved this by requiring you pick one block per ‘word’ & you can only switch to another block if separated by an underscore. As such you can do print_แมว but you couldn’t do pℝint_c∀t. This is a totally reasonable solution.

[–] NeatNit@discuss.tchncs.de 2 points 2 months ago

That's pretty cool

[–] lunarul@lemmy.world 2 points 2 months ago (1 children)

I can't imagine how something like homograph attacks can happen accidentally. If someone does this in code, they probably intended to troll other contributors.

[–] NeatNit@discuss.tchncs.de 3 points 2 months ago (1 children)

Multilingual users have multiple keyboard layouts, usually switching with Alt+Shift or similar key combo. If you're multitasking you might not realize you're on the wrong keyboard layout. So say you're chatting with someone in Russian, then you alt+tab to your source code and you spot a typo - you wrote my_var_xopy instead of my_var_copy. You delete the x and type in c. You forget this happened and you never realized the keyboard layout was wrong.

That c that you typed is now actually с, Cyrillic Es.

What do you say, is that realistic enough?

[–] lunarul@lemmy.world 4 points 2 months ago* (last edited 2 months ago) (1 children)

I use multilingual keyboard layouts, so I know that at least on Windows the selected layout is specific to each window. If I chat with someone in one language, then switch to my IDE, it will not keep the layout I used in the chat window.

But I also have accidently hit the combination to change layouts while doing something, so it can happen. I'm just surprised that Cyrillic с is on the same key as C, instead of S.

[–] NeatNit@discuss.tchncs.de 2 points 2 months ago

I believe there's a setting for whether it's global or per-window. Personally I prefer global, because I can't keep track of more than one state and I absolutely hate the experience of typing something and getting a different language than you expect.

[–] thevoidzero@lemmy.world 1 points 2 months ago (1 children)

Sorry, I forgot about this. I meant to say any sane modern language that allows unicode should use the block specifications (for e.g. to determine the alphabets, numeric, symbols, alphanumeric unicodes, etc) for similar rules with ASCII. So that they don't have to individually support each language.

[–] NeatNit@discuss.tchncs.de 1 points 2 months ago

Oh, that I agree with. But then there's the mess of Unicode updates, and if you're using an old version of the compiler that was built with an old version of Unicode, it might not recognize every character you use...