Live data from Hacker News

What every software developer must know about Unicode in 2023

tonsky.me

61–70 of 572 posts

Re: What every software developer must know about Unicode in 2023

#61

Unicode is a total mess. In a sane system, "extended grapheme clusters" would equal "codepoints" and it wouldn't make a difference for 99% of languages. Now we ended up with grapheme clusters, normalization, decomposition, composition, Zalgo text, etc. But instead of deprecating this nonsense, Unicode doubled down with composed Emojis.

What sort of practical issues are you running into due to Unicode's codepoint compositionality?

Normalization and the fact it is not forward-compatible.

Re: What every software developer must know about Unicode in 2023

#63
post #32

> Unicode is locale-dependent Well, there is a new fact that I learned and immediately hated. The fuck were authors thinking... I am now firmly convinced people developing unicode hate developers. I suspected it before just due to how messy it was (same character having different encodings ? Really ? Fuck you), but this cements it.

Yeah this is a big problem for me right now trying to pick fonts and characters for CJK. I have a bunch of bugs to fix that will require sending the locale down to the text itemization code.

Re: What every software developer must know about Unicode in 2023

#64
This is quite a good write up. An answer to one of the author's questions:

> Why does the fi ligature even have its own code point? No idea.

On of the principles of Unicode is round trip compatibility. That is you should be able to read in a file encoded with some obsolete coding system and write it out again properly. Maybe frob it a bit with your unicode-based tools first. This is a good principle, though less useful today.

So the fi ligature was in a legacy encoding system and thus must be in Unicode. That's also why things like digits with a circle around them exist: they were in some old Japanese character set. Nowadays we might compose them with some zwj or even just leave them to some higher level formatting (my preference).

Re: What every software developer must know about Unicode in 2023

#65
> many Chinese, Japanese, and Korean logograms that are written very differently get assigned the same code point

This leads to absolutely horrendous rendering of Chinese filenames in Windows if the system locale isn’t Chinese. The characters seem to be rendered in some variant of MS Gothic and it’s very obviously a mix of Chinese and Japanese glyphs (of somewhat different sizes and/or stroke widths IIRC). I think the Chinese locale avoids the issue by using Microsoft YaHei UI.

Re: What every software developer must know about Unicode in 2023

#66
post #41

What on EARTH is that mouse cursor thing all about? Why would you even bother writing this, then making it impossible to read properly?

It's tracking every visitors' cursor and sharing it with every other visitor. Why would a frontend developer demonstrate their ability to do frontend programming on their personal, not altogether super-serious blog? I meant that rhetorically but it's a flex. I agree, not the best design in the world if you're catering for particular needs, but simple and fun enough. You should check out dark mode. In that vein, I thi…

> Why would

because it shows that they don't understand important design aspects

while it doesn't really show off their technical skills because it could be some plugin or copy pasted code, only someone who looks at the code would know better. But if someone care enough about you to look at your code you don't need to show of that skill on you normal web-site and can have some separate tech demo.

> okay if we let people have fun

yes people having fun is always fine especially if you don't care if anyone ever reads your blog or looks at it for whatever reason (e.g. hiring)

but the moment you want people to look at it for whatever reason then there is tension

i.e. people don't get hired to have fun

and if you want others to read you blog you probably shouldn't assault them with constant distractions

Re: What every software developer must know about Unicode in 2023

#67

Earlier quoted context omitted.

What sort of practical issues are you running into due to Unicode's codepoint compositionality?

It's unnecessary complexity and a security nightmare. Have you ever tried to implement Unicode normalization? A single bug in your code and malformed text can crash your application or worse.

It's hard for me to imagine how Unicode normalization could crash your application unless you have very convoluted memory management code.

What on earth are you doing that it's leading to crashes? Are you not validating the result?

Re: What every software developer must know about Unicode in 2023

#68

> The only modern language that gets it right is Swift: I disagree. What is the "right" things is use-case dependent. For UI it's glyph bases, kinda, more precise some good enough abstraction over render width. For which glyphs are not always good enough but also the best you can get without adding a ton of complexity. But for pretty much every other use-case you want storage byte size. I mean in the UI you care abou…

Arguably, you don’t need any (default) length at all, just different views or iterators. When designing a string type today, I wouldn’t add any single distinguished length method.

Re: What every software developer must know about Unicode in 2023

#69

> The only modern language that gets it right is Swift: I disagree. What is the "right" things is use-case dependent. For UI it's glyph bases, kinda, more precise some good enough abstraction over render width. For which glyphs are not always good enough but also the best you can get without adding a ton of complexity. But for pretty much every other use-case you want storage byte size. I mean in the UI you care abou…

Swift string type has got many different views, like UTF-8, UTF-16, Unicode Scalar, etc… so if you want to count the bytes or cut over a specific byte you still can.

Re: What every software developer must know about Unicode in 2023

#70

> The only modern language that gets it right is Swift: I disagree. What is the "right" things is use-case dependent. For UI it's glyph bases, kinda, more precise some good enough abstraction over render width. For which glyphs are not always good enough but also the best you can get without adding a ton of complexity. But for pretty much every other use-case you want storage byte size. I mean in the UI you care abou…

That is why I like the way Raku handles it.

It has distinct .chars .codes and .bytes that you can specify depending on the use case. And if you try to use .length is complains asking you to use one of the other options to clarify your intent.

  my \emoji = "\c[FACE PALM]\c[EMOJI MODIFIER FITZPATRICK TYPE-3]\c[ZERO WIDTH JOINER]\c[MALE SIGN]\c[VARIATION SELECTOR-16]";
  say emoji; #Will print the character
  say emoji.chars; # 1 because on character
  say emoji.codes; # 5 because five code points
  say emoji.encode('UTF8').bytes; # 17 because encoded utf8
  say emoji.encode('UTF16').bytes; # 14 because encoded utf16
Post reply on HN