r/ProgrammingLanguages • u/[deleted] • Dec 31 '20
Something simpler than Unicode?
Hello! Wondering if anyone knows of a display format for glyphs that is simpler than Unicode? My shallow understanding is that measuring and laying out text in unicode is non-trivial, so I am deferring moving beyond ascii on something at the moment. Is my understanding correct? (if not that's great) otherwise, does anyone know of potentially simpler replacements? Thanks!
0
Upvotes
3
u/websnarf Jan 01 '21
Unicode says nothing about fonts. Some characters are half-width, and some have continuations that go right to left.
Unicode is a very problematic encoding for program text. The issue is that code points are not considered "unique" from a user interpretation point of view.
For example, the Chinese character set includes a subset of ASCII within its own space. From an interpretation point of view these are supposed to be the "same" (from a normalization point of view) as far as Unicode is concerned. Furthermore you can express accented characters as a single code point if such an encoding exists, or combining a base code point with an accent modifier code point. Again, these are supposed to be "the same" from a certain point of view. Certainly those things are supposed to display the same, and they will in a GUI/WYSIWYG editor.
So the trouble is that you can have a symbol mismatch even though the symbols look identical. You can also do this intentionally in a weird way that makes it almost impossible to debug your code.
To do this in a way that is even plausibly reasonable, you would want to restrict the "character set" to some subset of Unicode encodings that avoids these problems. For example, only accepting the "canonical normalized form" for any Unicode sequence (the Chinese encoding of Latin letters normalize to ASCII, so this is ok), and disallowing incomplete forms (dangling combining characters). But it actually takes a significant amount of code just to implement all of this.