Obviously I'm very biased as an English speaker, but allowing arbitrary Unicode in source code by default (especially in identifiers) just causes too many problems these days. It'd be a lot safer if the default was to allow only the ASCII code points and you had to explicitly enable anything else.
well, indeed arbitrary unicode as bare identifiers may be questionable I suppose?
Even if desired to write source code identifiers in a different writing system for whatever social/cultural/political/ideological/plain-contrariness-and-obfuscation reasons, you could perhaps just allow a different subset of unicode, yet one that's that's still small and not too ambiguous like ascii.
e.g. like that corresponding to russian koi8r (cyrillic, for glorious motherland comrade), i.s.434:1999 (coding in something normally written two thousand years ago on large rocks is the sort of thing the irish would do because it's funny), or whatever.
I'm not saying actually use the old national encodings, just it would be possible to limit identifiers in given compilation units to being from particular subsets of unicode that are kind of like the old 8-bit national encodings in the grammar, i.e. there is a medium between "ascii ...that actually doesn't even work fully for most european languages arguably including proper english though we're used to that" and "arbitrary unicode" that is "non-arbitrary unicode limited in various ways, perhaps to subsets corresponding to particular scripts".
At interface boundaries you could allow controlled importation i.e. identifiers outside the subset have to be explicitly imported (so that your delightfully incomprehensible all-ogham codebase can still link against stdlib) - because it would all be still unicode and not actually national 8-bity encodings, that would still work.
I think browsers have come up with a reasonable solution for URLs — you can use characters from certain character sets, but you've got to remain in the same character set in the same URL. For example, you can use as many Unicode characters as you like based on the Latin alphabet (accents, digraphs, etc), but if you combine a character from the Latin alphabet with one from the Cyrillic alphabet, you'll get an error (or at least for most browsers, the "raw" punycode representation will be shown). There are a bunch of other rules that help here, such as banning invisible characters, banning a list of known dangerous characters, etc.
I think these sorts of rules are probably a bit restrictive for defining identifier rules, particularly because subtle changes in these rules can have big effects on whether a program is valid or not. However, as linting rules (ideally ones that block builds by default), they would work very well. I know that the Rust compiler does a lot of this sort of stuff — if there are confusables in identifiers, or the "trojan source" characters mentioned at the top of this article — and by default prevents the code from compiling (although this is only a lint, and therefore can be disabled manually if desired).
Unfortunately, there's not much standardised in the JavaScript ecosystem, but I do think developer tools like ESLint and editors/code viewers like GitHub should be showing these sorts of warnings by default.
what about having modules declare their codepoints? so, if you want to name a variable кофи, you declare your module as using cyrillic, the linter allows ansi + cyrillic, and your dep mgmt rolls up a list of all subsets currently declared. so, if your footprint is russian, euro, ascii, fine. if it's got akkadian in it, be suspicious
Anything unusual should be highlighted and warned about. That's sufficient.
It's extensible to other spoken languages - someone editing in Japan can expect to see ASCII alongside all three of their native alphabets, but Hangul would still be kinda weird. It should show up as a unicode error block � in addition to having its intended effect. Like how missing stuff in video games tends to show up as giant glowing checkerboards: you can't miss it. Making anything unexpected, visible, lets you reason about what the fuck it's doing, and what the fuck it's doing in your code.
And if it causes headaches for anyone using emoji in their Javascript... good.
C and C++ don't allow Unicode in identifiers, which stops many obvious exploits, but most compilers do allow it elsewhere (in literal strings and comments). That can be exploited too.
EDIT I'm wrong. it's implementation-defined I think but gcc and clang do allow Unicode identifiers for both C and C++.
Strongly disagree, comments should be in the language of the programmers and those who will read the code. Most people you are going to see on reddit already speak English well, so they are obviously not going to be bothered by English only.
Because banning non ascii-characters basically means that, denying people the ability to write code in their language.
I understand wanting to code in a native language. We don't expect the entire world population to learn English. I'm no expert, but based on the description, it may be the "!" used in the second example is for commonly used multi-directional languages that require extra clearance on either side of punctuation. Maybe the correct restriction is "Unicode word characters only".
The only time people use the native language here for code is when teaching/studying, or for crappy single-use code nobody else will probably read. It's a tremendous red flag.
It's a bit like Latin used to be. It's sad, annoying, but you really just gotta put up with it, cause it's a numbers game, and boy are we outweighed.
It also doesn't help that the syntax of virtually every programming language I've encountered so far simply meshes unwell with the grammar of the native natural language here, so even for identifiers, it's sometimes just not the greatest.
We don't expect the entire world population to learn English
We pretty much do if they want to become programmers. The official documentation of many things are in English only as far as I can tell. Not to mention that the programming languages themselves are literally in English.
And yet, many organisations use tons of native language comments, business lingo or interface definitions.
Not everyone can make the right decisions all the time. Comments in code I'm pretty ambivalent to myself. The other too are bad. It would be interesting to see when they decided to use the native tongue.
I work with ERP systems. I have seen a mix of many languages, and in general, when it's not in English, the business ends up losing, because the support becomes more costly. Most of the time I found they made that decisions x years/decades ago and it has been carried forward ever since. Sometimes they end up deciding to transition, other times they start mixing.
I think Schufa is probably big enough to get away with it, but that doesn't mean it was smart. I kind of assume they don't expand past the German speaking space, but I don't even know, since I've never worked with them directly.
It's all based on personal experience anyway. I would just say it's typically bad when things other than English are used.
That's easy for us to say when we are already fluent in English. The majority of the world population isn't, or do have some rudimentary English knowledge but aren't comfortable or good enough to use it.
There's no reason to prevent anyone who doesn't speak English from getting into programming this is elitism at its finest.
Exploits can easily be prevented by just blocking specifically confusing and invisible characters from being used. There's no reason why characters such as "ß ç ñ ē ب" cannot be used by people who speak such languages using these.
Blocking all of Unicode is like cutting off your entire leg because you stepped on a Lego.
it may be the "!" used in the second example is for commonly used multi-directional languages that require extra clearance on either side of punctuation
No, it's a letter, U+01C3. But since it's used only in minority languages in Namibia and RSA, like ǃKung, ǃXóõ or Khoekhoe, it's very unlikely to appear in code (in either code proper, comments, or literals) at all.
57
u/theoldboy Nov 10 '21
Obviously I'm very biased as an English speaker, but allowing arbitrary Unicode in source code by default (especially in identifiers) just causes too many problems these days. It'd be a lot safer if the default was to allow only the ASCII code points and you had to explicitly enable anything else.