3 ms·
I'll also play along the role of the pedant : > In a go a string is an immutable byte slice assumed to be valid utf8, with associated methods and users which
by jrimbault 6y ago
I'll also play along the role of the pedant :
> In a go a string is an immutable byte slice assumed to be valid utf8, with associated methods and users which all assume that slice of memory is valid utf8.
Which is in my opinion the worst choice you could make when designing a type. If I'm working in a typed language because of so-called "type safety", if I can't trust my types to actually enforce their guarantees, what can I trust ?
- papaf 6y agoIts a common mistake to assume strings are UTF-8 but it is a mistake. This is not a defence of Go but more of a warning to Go programmers.
- adonovan 6y agoExactly. It's a convention, not a law of physics. If a string's UTF-8 validity is important to the correctness of your function, check it. It's not expensive.