4 ms·
I'm Chinese, and I prefer UTF8 to UTF16. > You might think "but BOMs are super evil." Checking a BOM is extremely, extremely easy. Furthermore, you don't get t
by netheril96 4y ago
I'm Chinese, and I prefer UTF8 to UTF16.
> You might think "but BOMs are super evil." Checking a BOM is extremely, extremely easy. Furthermore, you don't get to bail out of checking anything just by using UTF-8, you have to check to ensure you have _valid_ UTF-8. That's right, you gotta scan the whole bytestream anyway, so you may as well just check the 2-byte BOM at the beginning too.
BOM breaks substring. Everything you take a substring, you need to prepend a BOM if you want to serialize it to somewhere else. If you want to concat two strings with BOM, you need to remove one of them. All of these are unnecessary pains.
> You might also think "OK OK, you could be right, but what about HTML, which is mostly ASCII and would nearly double in size if it went from UTF-8 to UTF-16." Practically all HTML is gzipped, so the difference is pretty small, plus the majority of text isn't HTML (almost anything stored in a database, almost anything in a file on your computer, etc.)
This just contradicts your own reasoning that UTF-16 is better for East Asians due to size savings.
- camgunz 4y agoSubstrings just get the BOM too. EZ. Re: HTML, people usually bring it up because it's a lot of ASCII that'll all double up under UTF-16. Mostly my argument is that most text isn't HTML, so size savings on other text files still matter.
- netheril96 4y agoWhich standard string library ever does that?
- camgunz 4y agoAre there UTF-16 string libraries that let you split a UTF-16 string into a string with a BOM and a string without it? That would feel like a bug to me.
- bjoli 4y agoThat is a minor nuisance when dealing with raw bytes. Any sane language representation would probably store it as a separate field egen not on the wire. I would probably do BOM, LUT, BYTES. Where LUT is a lookup table of indices for every 64 chars so that you could do o(1) random access for the vast majority of cases.