4 ms·
I do love the simplicity of Go's UTF-8[0] approach, though this did also burn me when I was first learning the language and did not really understand the implic
by jd3 6y ago
I do love the simplicity of Go's UTF-8[0] approach, though this did also burn me when I was first learning the language and did not really understand the implication of it.
I translated an x-face encoder from js to go for one of my introductory projects and initially couldn't get the correct output from `b64.StdEncoding.EncodeToString` due to the fact that x-face strings are single-byte ASCII ISO-8859-1 encoded[1].
[0]: https://blog.golang.org/strings https://blog.golang.org/strings
[1]: https://stackoverflow.com/questions/43461679/escaping-of-hex-values-in-string-literals https://stackoverflow.com/questions/43461679/escaping-of-hex...
- jeff-davis 6y agoAfter reading [0], I was left with the question: why not just have a utf-8 string type in addition to a byte string type? Also, as a nit, I don't think iso-8859-1 is ASCII.
- jd3 6y ago> why not just have a utf-8 string type in addition to a byte string type? I'm not a go expert, but my understanding is that go "strings" are really all just a series of bytes and it's the standard library functions which treat string operations as UTF-8 encoded by default. I think this reddit post[0] explains it nicely. I suppose the simplicity of "just work with the bytes and apply encoding when necessary" follows go's simplicity and composability/interface patterns well. > Also, as a nit, I don't think iso-8859-1 is ASCII. We're splitting hairs here, but ISO-8859-1 is the eight-bit extension to 7-bit ASCII, no? It includes the standard 128 ASCII characters + up to an additional 128 characters (191 in total for ISO-8859-1 Latin-1 Western European, iirc). [0]: https://old.reddit.com/r/golang/comments/a5v3fn/are_strings_utf8_by_default/ebprjpk/ https://old.reddit.com/r/golang/comments/a5v3fn/are_strings_...