4 ms·
> UTF-16 is mostly a “worst of both worlds” compromise at this point, and the main programming language I can think of that uses it (and exposes it in this form
by wereHamster 4y ago
> UTF-16 is mostly a “worst of both worlds” compromise at this point, and the main programming language I can think of that uses it (and exposes it in this form) is Javascript, and that too in a broken way.
Unicode predates JavaScript. JS use UCS-2!
From https://mathiasbynens.be/notes/javascript-encoding https://mathiasbynens.be/notes/javascript-encoding
JavaScript engines are free to use UCS-2 or UTF-16 internally. Most engines that I know of use UTF-16, but whatever choice they made, it’s just an implementation detail that won’t affect the language’s characteristics.
The ECMAScript/JavaScript language itself, however, exposes characters according to UCS-2, not UTF-16.
- morelisp 4y agoLike all UCS-2 users, it is using UTF-16 today. Strings are sequences of UTF-16 code units. (If you don't believe me, you can verify this by seeing that emoji exists.) The link uses the abhorrent term "characters" far too frequently to be saying anything meaningful.
- account42 4y agoLike all would-be UTF-16 users it actually uses WTF-16 in practice.
- chrismorgan 4y agoI never liked Mathias’s description there. A better description is that JavaScript uses unvalidated UTF-16, with UTF-16 code unit indexing and access in most places. (Notwithstanding this, new functionality in the language tends to use Unicode scalar values where possible, e.g. string iterator decodes valid surrogate pairs.)