2 ms·
The biggest disadvantage of UTF-16, IMO, is that programmers blindly assume that they can index into the string as if it were an array, and get a code point out
by deathanatos 10y ago
The biggest disadvantage of UTF-16, IMO, is that programmers blindly assume that they can index into the string as if it were an array, and get a code point out — which you can not; you'll get a code unit, which is slightly different, and might not represent a full code point (let alone a full character).
UTF-8's very encoding quickly beats this out of anyone who tries, whereas it's easy to eek by in UTF-16. The real problem is that the APIs allow such tomfoolery. (Some have historical excuses, I will grant, but new languages are still made that allow indexing into code units without it being obvious that this is probably not what the coder wants.)
- int_19h 10y agoStrictly speaking, this is a disadvantage of languages that have strings as first-class types and allow indexing on strings in the first place (and specify it to have this semantics). For the most part, the developer shouldn't really care about the internal encoding of the string, but the language/library should also not expose that to them.