Of course, there's a long ways to go from "a sequence of valid code units" to "a valid string," but it's still relevant.
what about surrogate pairs? You can't have only one 16 bit word for a pair and have a valid UTF-16 sequence. This problem is real easy to do if you substring a UTF-16 sequence naively.
In what sort of situation that is a problem?
There's a related issue with "non-shortest forms:" it's possible to encode the NUL character '\0' without actually using a null byte. This means that (for example) "round tripping" UTF-8 data can introduce a null byte, allowing for security exploits when mixed with C-style string processing.
But what I wrote is nevertheless correct, and matters. See for example the special requirements on UTF-8 processing in D93:
If the converter encounters an ill-formed UTF-8
code unit sequence...it must not consume the
successor bytes as part of the ill-formed
subsequence whenever those successor bytes
themselves constitute part of a well-formed UTF-8
code unit subsequence....For a UTF-8 conversion
process to consume valid successor bytes is not
only non-conformant, but also leaves the converter
open to security exploits."
"Ill-formed code unit sequence" is not possible with UTF-16. That's an advantage. Also note the last line: the existence of ill-formed code units has security implications that are not present with UTF-16.To be fair, UTF-16 has its own unique issues too, like endianness.
> I'm sure Ken Thompson and Rob Pike will be happy to hear someone thinks that way.
If that's the case then I think the designers of GB18030 deserve it more, because they achieved an encoding that is able to map all Unicode codepoints while being backwards compatible with GB2312, which is itself backwards compatible with ASCII.
But seriously UTF-8 is like sliced bread after having dealt with we-thought-64K-is-enough-so-lets-all-use-16-bits UCS-2/UTF-16.