News for hackers. Stuff that matters.
Re:Unicode sorting is hard and why browsers added special em... by jrochkind1 on Sunday June 27, 2021 @11:50PM (#27657954)
The takeaway is not "unicode is overly complex", it's that an algorithm for sorting strings consisting of any possible human language characters is super convoluted, and it's pretty amazing that unicode gives us a standard collation algorithm including localizations, that works remarkably well.

But... is complicated enough to implement that many environments apparently haven't felt there was enough demand to do so?

Re:Unicode sorting is hard and why browsers added special em... by pilif on Monday June 28, 2021 @05:09AM (#27659569)
> algorithm for sorting strings consisting of any possible human language characters is super convoluted

not only that: it's different depending on locale and sometimes context (in Germany there's a distinction of whether you sort for a phone book listing or not).

Doing it right requires basically shipping a huge database with locale specific information which is seen as "bloat" by many projects and thus made optional or not available at all.

>and it's pretty amazing that unicode gives us a standard collation algorithm including localizations, that works remarkably well.

it's not good enough in many cases. Thankfully there's ICU, but many environments frown upon that because it's seen as bloated. If sorting works "fine" for US-ASCII, why link to a 60MB library?

Re:Unicode sorting is hard and why browsers added special em... by jrochkind1 on Monday June 28, 2021 @07:41AM (#27660548)
I meant to include ICU in what I was saying works well when I said "unicode gives us a standard collation algorithm including localizations".

ICU stands for "International Components for Unicode." ICU collation is an implementation of the Unicode Collation Algorithm (which is really a suite of algorithms, or an algorithm with various parameterized branches), using the Unicode Common Locale Data Repository for localization -- that's also unicode, the CLDR is a unicode thing too, part of unicode. It's all unicode.

There are other implementations than ICU -- although maybe none as complete, because it is a lot/expensive, indeed. But ICU is an implementation of unicode algorithms. But for instance, unicode collation is also implemented -- in a way that will be the same as ICU modulo bugs or details the standard leaves up to implementations to vary -- in pure ruby by https://github.com/twitter/twitter-cldr-rb#sorting-collation

Re:Unicode sorting is hard and why browsers added special em... by jrochkind1 on Monday June 28, 2021 @09:38AM (#27661800)
PS: Did you know the unicode collation algorithms also includes a way to produce a sequence of bytes for a unicode string, such that sorting the produced sequence of bytes in strict byte order will produce the proper collation order for the original strings?

Which is how you implement high-performance unicode collation sorting in say a db.

Unicode is a very well-designed thing!

Re:Unicode sorting is hard and why browsers added special em... by dolmen on Monday June 28, 2021 @11:16AM (#27663011)
So, do you mind sharing the name of that transformation?
Re:Unicode sorting is hard and why browsers added special em... by shellac on Monday June 28, 2021 @06:26AM (#27660016)
The only language / framework I've used that seemed to get this right is OpenStep / Cocoa, which is presumably why Swift is mentioned as being 'notable'.

NSString would occasionally come up in performance analysis as being strangely slow compared with other languages, but this was because various operations like comparisons followed unicode.

Re:Unicode sorting is hard and why browsers added special em... by nabla9 on Monday June 28, 2021 @03:01AM (#27658861)
Unicode is overly complex, but sorting is not the reason.

Unicode is overly complex at grapheme cluster level.