3 ms·
Well, the first question is what a string's internal representation should be, and they went with UTF8. Once you've decided on UTF8, the question is whether to
by skybrian 13y ago
Well, the first question is what a string's internal representation should be, and they went with UTF8. Once you've decided on UTF8, the question is whether to hide the representation or expose it. If you decide to expose it, there's hardly any difference between an immutable byte array and string, so it's simpler in a way to have one type that can be used both ways.
- dsymonds 13y agoNo, read the article more carefully. A Go string's internal representation is a sequence of bytes. There's nothing UTF-8 about it.
- skybrian 13y agoI understood the article just fine. It's not wrong to say that in Go, text (called strings in other languages) is nearly always represented in UTF8 format and is commonly stored in variables of type string, or sometimes []byte. Perhaps I should have left out the word "internal" since it's exposed.
- dsymonds 13y agoYes, "internal representation" has a specific meaning. If you had said "standard representation" or something then I would have agreed with you.
- dchest 13y agoYes, there is: range on a string works on runes by decoding UTF-8.
- dsymonds 13y agoThat has nothing to do with "a string's internal representation". That is just how a range loop is defined/implemented.