5 ms·
You're confusing things. Strings cannot be utf-8 any more than you can be your signature. "strings" are abstract data structures. They are lists of character
by adamtj 14y ago
You're confusing things. Strings cannot be utf-8 any more than you can be your signature.
"strings" are abstract data structures. They are lists of characters. Not bytes, not integers, but characters. Often, we use the Unicode character set as the set of allowable characters. There are other character sets.
Internally, strings often represent characters as integers. When using the Unicode character set, strings then use the Unicode encoding to integers (a table mapping characters to unique numbers). Sometimes we use other character sets and encodings.
Unfortunately, integers are abstract. You can't store them in a file or transmit them over a network until you pick a concrete representation as bytes. How many bits per integer? Big or little endian? Etc. That's where UTF-8 comes into play.
UTF-8 is a merely a compressed data format used to represent a sequence of integers as a sequence of bytes - a way that happens to have some properties that make it convenient for representing strings.
UTF-8 is not Unicode.
UTF-8 can also be used for other types of numerical data. As a silly example, suppose you had a list of ages of houses. Many houses are less than 100 years old. A few are more than 300 years old. An efficient serialization of that data would be to represent the ages as integers and then utf-8 encode your list of integers.
Some true statements: A character set is a set of characters. Characters are not integers or bytes. A mapping from characters to integers is an encoding. Unicode is a standard that defines a character set and an encoding to integers. Mapping integers to bytes is confusingly also called encoding. UTF-8 is an encoding from integers to bytes. Unicode defines a set of characters and an encoding of characters to integers. UTF-8 is an encoding of integers to bytes. UTF-8 is not Unicode.
- paulsutter 14y agoI'm just saying that if we standardize on encoding, we dont need to talk about encoding. Which is my interpretation of the original document. Separate point: There is no such thing as an abstract string or integer in a computer, no matter what language you are using. Every string in a computer has an encoding - you have to store it as ones and zeros. If we standardize on UTF-8 as an encoding, we just dont need to use the awkward phrase "UTF-8" in ordinary conversation.