News for hackers. Stuff that matters.
Re:Unicode sorting is hard and why browsers added special em... by nitwit005 on Monday June 28, 2021 @01:55AM (#27658554)
Even English has no defined ordering for all characters. What is the ordering of punctuation marks? Do upper case or lower case letters go first? How do you deal with white space characters?

ASCII ordering is just an arbitrary standard that mapped numbers to letters so people could make computer hardware interoperate. It's not always a sensible sort ordering.

Re:Unicode sorting is hard and why browsers added special em... by tyingq on Monday June 28, 2021 @02:29AM (#27658716)
Pedantic, I know, but the original 1963 ASCII document did speak a lot about collation and ordering. Perhaps a lot of it doesn't make sense today, but the sort order wasn't accidental.

http://www.bahaistudies.net/asma/ascii.pdf

Re:Unicode sorting is hard and why browsers added special em... by thaumasiotes on Monday June 28, 2021 @02:53AM (#27658820)
> Even English has no defined ordering for all characters. What is the ordering of punctuation marks? Do upper case or lower case letters go first? How do you deal with white space characters?

This isn't really true; there are well-defined, standardized answers to all of those:

- For purposes of alphabetizing, punctuation marks are completely ignored, as if they weren't present. "Stop me!" and "Stop, me!" are identical strings.

- Case is also ignored. "AAAAAGH" and "aaaAagh" are identical strings.

- Spaces are not ignored. Sort order is determined by the text before the first space. Shorter sorts before longer. "A bird", "a cat", and "a deer" all sort under "a" and above "ab".

Note that these are rules for English, not rules for arbitrary sequences of binary data. They look the way they do because they model the data as a sequence of English words.

Re:Unicode sorting is hard and why browsers added special em... by crazygringo on Monday June 28, 2021 @11:14AM (#27662989)
It's not really well-defined if "ignored" means "sort arbitrarily".

You can't just say "Stop me!" and "Stop, me!" are identical. You have to define which comes first.

Re:Unicode sorting is hard and why browsers added special em... by thaumasiotes on Monday June 28, 2021 @02:40PM (#27665859)
> You can't just say "Stop me!" and "Stop, me!" are identical. You have to define which comes first.

Why? All real-world applications of sorting must handle sorting identical objects. Saying that "Stop me!" and "Stop, me!" are identical doesn't cause any problems that aren't also caused by saying "Stop me!" and "Stop me!" are identical.

Re:Unicode sorting is hard and why browsers added special em... by crazygringo on Monday June 28, 2021 @04:03PM (#27667155)
But they're not identical, they differ by a comma.

It's a desired feature of sorting algorithms that they should be deterministic, in which case arbitrarily ordered input should produce identical output.

Otherwise, having non-deterministic output just makes everything harder -- harder to make comparisons, more work to write tests, etc.

Re:Unicode sorting is hard and why browsers added special em... by thaumasiotes on Monday June 28, 2021 @07:45PM (#27669805)
> But they're not identical, they differ by a comma.

This makes as much sense as saying that "Stop me!" and "Stop me!" aren't identical, because one of them is first and the other is second.

It's true, but it's not relevant to sorting them.

Your "desired feature of sorting algorithms" is most commonly realized as the question of whether the algorithm provides a "stable" sort -- that is, whether two values that compare equal are guaranteed to occur in the same order in the (sorted) output that they did in the (unsorted) input. There are applications where this is considered desirable, and many other applications where it isn't. But there are no applications in which it's not possible for two values to compare equal. For the question of stable sorting to arise in the first place, you have to have already realized that you're going to be sorting things that compare equal.

Re:Unicode sorting is hard and why browsers added special em... by crazygringo on Monday June 28, 2021 @08:21PM (#27670065)
...which is why it's generally desirable for unequal things to never compare equal.

Stability is about preserving the order of items that compare equally. That's a different topic.

I'm talking about it being desirable not to underspecify the comparison function (sorting rules), so that unequal items are never compared as equal.

Re:Unicode sorting is hard and why browsers added special em... by kps on Monday June 28, 2021 @10:30AM (#27662468)
‘Shorter sorts before longer’ is the reason ASCII puts space first and textual punctuation before alphabetics.
Re:Unicode sorting is hard and why browsers added special em... by mjevans on Monday June 28, 2021 @02:27AM (#27658704)
The way most native English speakers (and writers) that I know, including myself, would sort such a set is to ignore the set (regexp) \W . The 'C' (blind bit sorting) Locale is more sensitive and a suitable default for simple machine focused environments.

E.G. of sorting how English humans tend to:

`A string with non-letters ignores the non-letters.

Ace