3 ms·
> If you ask the machine it's an array of integers Not sure what you mean by this. A string is an array of bytes, in the way that literally every array is an a
by dahfizz 6y ago
> If you ask the machine it's an array of integers
Not sure what you mean by this. A string is an array of bytes, in the way that literally every array is an array of bytes, but its not "implemented" with integers. Its a UTC-encoded array of bytes.
And what is the information that is encoded in those bytes? Codepoints. That's what UTF does, it lets us store unicode codepoints as bytes. There is a reasonable argument that the machine, or at least the developer, considers a string as an array of codepoints.
- ChrisSD 6y agoUTF-8 is an array of bytes (8 bit integers). UTF-16 is an array of 16 bit integers. UTF-32 is an array of 32 bit integers. The machine doesn't know anything about code points. If you want to index into the array you'll need to know the integer offset.
- dahfizz 6y ago> The machine doesn't know anything about code points. If you want to index into the array you'll need to know the integer offset. The machine doesn't know anything about Colors either. But if I defined a Color object, I would be able to put Color objects into an array and count how many Color objects I had. You're being needlessly reductive. > UTF-8 is an array of bytes (8 bit integers) UTF-8 encodes a codepoint with 1-4 single-byte code units. The reason UTF-8 exists is to provide a way for machines and developers to interact with unicode codepoints. Is a huffman code an array of bits? Or is it a list of symbols encoded using bits?
- ChrisSD 6y agoYou seem to be thinking of the abstraction as a concrete thing. A code point is like LLVM IR; an intermediary language for describing and converting between encodings. It is not a concrete thing in itself. The concrete thing we're encoding is human readable text. The atomic unit of which is the user perceived character. I'm curious, what use is knowing the number of code points in a string? It doesn't tell the user anything. It doesn't even tell the programmer anything actionable.