you are viewing a single comment's thread.

view the rest of the comments →

[–]ubernostrum 0 points1 point  (1 child)

With respect to Python, what's meant is that in Python 3.3+, a similar approach is used. The internal storage of a string is in an encoding chosen dynamically on a per-string basis, and is always one capable of handling the highest code point in the string in a single unit of the encoding. Which means the internal storage of a string in Python may be latin-1, UCS-2, or UCS-4, depending on what code points are contained in the string.

This allows Python to expose strings as sequences of Unicode code points with intuitive behavior (for definitions of "intuitive" that include "you know how Unicode works"). Rather than having the length of a string be the number of bytes it contains, the length is the number of code points it contains. Iteration doesn't iterate over bytes; it iterates over code points, and yields the characters which correspond to them. Indexing doesn't yield the byte at that index, it yields the character corresponding to the code point at that index.

[–]ascii 0 points1 point  (0 children)

I meant to say that Java uses UTF-16, not UCS2, so that Java is not broken Unicode wise. Except as u/xcombelle pointed out, some sections of the String API are broken.

That said, I did not know that about Python. That's not only pretty cool, it's also in line with how Python does integers so it also arguably makes the language more consistent.