Live data from Hacker News

When I say “alphabetical order”, I mean “alphabetical order”

sebastiano.tronto.net

91–100 of 385 posts

Re: When I say “alphabetical order”, I mean “alphabetical order”

#91

I agree with Microsoft/Google/KDE's order. The author's situation is extremely rare, and the situation where someone wants "10" to be before "9" is far more common. Moreover, desktops don't label this sorting "alphabetical" (E: and it would really be "lexicographic"*), they label it "by name" (an informal criteria), so technically they're not lying. > I miss the time when computers did what you told them to, instead…

Both should be supported. Perhaps put the uncommon (true alphanumerical order) behind a nested menu or something. But the mind-reading-less option should be there.

> Both should be supported.

At least in KDE they are, and you can pick whether you want natural or alphabetical sorting (which has a case sensitive and insensitive variant).

Re: When I say “alphabetical order”, I mean “alphabetical order”

#92
Sorting by name (collation) is waaay tricker than simply figuring out how to parse the numbers.

The International Components for Unicode library implements the Unicode Collation Algorithm, which depends on the language code and region of the locale, and looks up the quirks for each locale in the Common Locale Data Repository.

It's a much better idea to just use the standard ICU library or platform specific libraries (which are often build on ICU like JavaScript's Intl.Collator), instead of trying to hot dog it by rolling your own.

International Components for Unicode

https://en.wikipedia.org/wiki/International_Components_for_U...

>ICU provides the following services: Unicode text handling, full character properties, and character set conversions; Unicode regular expressions; full Unicode sets; character, word, and line boundaries; language-sensitive collation and searching; normalization, upper and lowercase conversion, and script transliterations; comprehensive locale data and resource bundle architecture via the Common Locale Data Repository (CLDR); multiple calendars and time zones; and rule-based formatting and parsing of dates, times, numbers, currencies, and messages.

Unicode Collation Algorithm

https://en.wikipedia.org/wiki/Unicode_collation_algorithm

>The Unicode collation algorithm (UCA) is an algorithm defined in Unicode Technical Report #10, which is a customizable method to produce binary keys from strings representing text in any writing system and language that can be represented with Unicode. These keys can then be efficiently compared byte by byte in order to collate or sort them according to the rules of the language, with options for ignoring case, accents, etc.[1]

>Unicode Technical Report #10 also specifies the Default Unicode Collation Element Table (DUCET). This data file specifies a default collation ordering. The DUCET is customizable for different languages,[1][2] and some such customizations can be found in the Unicode Common Locale Data Repository (CLDR).[3]

Common Locale Data Repository

https://en.wikipedia.org/wiki/Common_Locale_Data_Repository

>The Common Locale Data Repository (CLDR) is a project of the Unicode Consortium to provide locale data in XML format for use in computer applications. CLDR contains locale-specific information that an operating system will typically provide to applications. CLDR is written in the Locale Data Markup Language (LDML).

>Among the types of data that CLDR includes are the following:

  Translations for language names
  Translations for territory and country names
  Translations for currency names, including singular/plural modifications
  Translations for weekday, month, era, period of day, in full and abbreviated forms
  Translations for time zones and example cities (or similar) for time zones
  Translations for calendar fields
  Patterns for formatting/parsing dates or times of day
  Exemplar sets of characters used for writing the language
  Patterns for formatting/parsing numbers
  Rules for language-adapted collation
  Rules for spelling out numbers as words
  Rules for formatting numbers in traditional numeral systems (such as Roman and Armenian numerals)
  Rules for transliteration between scripts, much of it based on BGN/PCGN romanization
Tricky collation examples:

sv-SE (Swedish): å, ä, ö are separate letters at the end of the alphabet, not variants of a or o.

de-DE (German): ä, ö, ü may sort as ae, oe, ue in some contexts, or as distinct letters. ß sometimes sorts as ss.

tr-TR (Turkish): dotted i (i) and dotless ı are different letters; I sorts with ı, not with i.

es-ES (Spanish): traditionally ch and ll were treated as single letters with their own place in the alphabet.

cs-CZ (Czech): ch still counts as a unique letter, sorted after h.

da-DK / no-NO (Danish/Norwegian): ø comes after z.

is-IS (Icelandic): þ (“thorn”) is part of the alphabet, after z.

fr-FR (French): accents usually ignored in sorting, so é = e, but not always depending on collation settings.

el-GR (Modern Greek): tonos accents, final sigma ς vs. σ, etc.

nl-NL (Dutch): the digraph “ij” is often treated as a single letter, and capitalized as “IJ”. In dictionaries and phone books it often sorts as a single letter under “I”, but sometimes is listed after “X” depending on tradition.

Then you get into non-Latin languages like, Chinese, Japanese, and Korean collation, which gets hairy with radicals, kana order, and stroke count.

Also different locales have different ways of representing numbers, like switching between "," and "." as separators and decimal points.

ICU supports integer only "natural" numeric collation, so anything more complicated like versions, floating point, negative numbers, hex, thousands separators, fractions, roman numerals, etc, you'd have to build on top of ICU.

ICU doesn't support incomprehensible dead languages like Latin or Ancient Greek (it does however support French ;). It does support Roman numeral formatting, but not collation, which would be pretty tricky and ambiguous.

https://www.youtube.com/watch?v=sKWvTlLMB-Y

A nuanced but common example that ICU/UCA/CLDR helps with is a menu to select the current locale: you have to translate each language's name into the current locale, and also sort them in the current locale. On top of different collations they can also have totally different spellings, like "United States of America" is "Verenigde Staten van Amerika" in Dutch. This makes it challenging for users to find their own language when the locale is set wrong! You just can't win.

Not to mention emojis! Which comes first: The chicken or the egg? The taco or the poop?

Also, the Mac Finder switches ":" and "/" for historical reasons (HFS used to use ":" as a directory separator instead of "/"), so you can create a file name like "9/11 Attack" in the Finder, which actually gets the underlying Unix filename "9:11 Attack". Don't believe me? Rename a file in the Finder to include a slash, which you know is impossible to represent as a Unix file name. Then go "ls" the directory in the shell.

The Mac Finder weirdly collates "/" after "9" because under the hood it’s really storing it as ":", which sorts before "0". But it also has other punctuation collating inconsistencies, sorting "," and ";" and others after "0" too. Definitely not ASCII order -- I'm not sure what rules it uses, but it's different than "ls".

However, while it's generally true you can't have "/" in Unix file names, NFS used to trustingly let clients rename Unix files to include a "/" in their name, which the Gator Box AppleTalk/Ethernet gateway let you do with the Mac Finder (pre OS/X), which would silently corrupt your "dump" backups on the Unix NFS server, so you would not learn about it until you tried to retrieve your files and "restore" crashed.

https://news.ycombinator.com/item?id=31821646

>Another reason that NFS sucks: Anyone remember the Gator Box? It enabled you to trick NFS into putting slashes into the names of files and directories, which seemed to work at the time, but came back to totally fuck you later when you tried to restore a dump of your file system.

>The NFS protocol itself didn't disallow slashes in file names, so the NFS server would accept them without question from any client, silently corrupting the file system without any warning. Thanks, NFS!

Re: When I say “alphabetical order”, I mean “alphabetical order”

#93
post #50
post #35

> Well, apparently all these operating systems have decided that no, users are too dumb and they cannot possibly understand what alphabetical order means. So when you ask them to sort your files alphabetically, they don’t. Instead, they decide that if some piece of the file name is a number, the real numerical value must be used. Well, no. You don't actually ask them to sort in alphabetical order. You ask them to sor…

> And they choose the interpretation that (per their reasoning, and possibly some actual data) seems most likely to correspond to what the user wants. Yes, that make sense, but the problem is that this interpretation changed in the last 10 (15? 20?) years. It used to be that "by name" meant "by name, il alphabetical / lexicographical order" in pretty much every file manager.

[deleted]

Re: When I say “alphabetical order”, I mean “alphabetical order”

#94
post #60

Earlier quoted context omitted.

I'm not sure I agree. I think I could be convinced if there was a unique and universal representation for numeric values using characters. But we have so many textual representations of numeric values that I'm assuming the "mind-reading" goodness only works for a small subset. And the subset will be somewhat intuitive for developers but unlikely to be so for non-technical people. For example, does the order handle nu…

Are filenames likely to include those representations? I feel like probably not (can you even include commas in Windows filenames?) More to the point of the article--if you want things sorted by date, sort by date. I think most laypeople aren't looking at long CHAR1234_5678 filenames anyway, they're looking at thumbnails and dates.

The most common date format used in Europe uses period separators so can often appear in filenames. Commas are probably more rare. Things like versions are often fractional like v1.3 or v1.11 and can appear embedded in filenames.

Re: When I say “alphabetical order”, I mean “alphabetical order”

#95
post #90
post #79

Earlier quoted context omitted.

Ah, the classic filenames with decimal points and scientific notation in them, so common...

Here's a different scenario: filenames with dates in them. Consider September Budget and October Budget . September is the equivalent of 9, October of 10. Which comes first for natural sorting? Remember, the file modify date may not be useful here since you may have wrapped up the September budget on October 1st while the prior edit to the October budget may have been on September 20th. The problem is that there is n…

the one true way: budget_09.csv, budget_10.csv

Re: When I say “alphabetical order”, I mean “alphabetical order”

#96
In Total Commander, there is a function in the options to sort strict by numerical char code. It will sort those files correctly. Unfortunately, it will also sort "10.txt" before "2.txt".

---

In all file managers, I miss an API point where one can give a userdefined sorting function for the file and folder list.

Re: When I say “alphabetical order”, I mean “alphabetical order”

#97
Plex team, are you reading this?

For some inexplicable reason, Plex just throws its hand up on non-ASCII characters and puts them first.

In Norway we have three extra letters, æøå, and they're at the end of the alphabet after z. But in Plex, I have Øystein Sunde[1] placed before any other in my music library.

Now in the 1990s I would forgive US software for such a thing, but it's 2025...

[1]: https://en.wikipedia.org/wiki/%C3%98ystein_Sunde

Re: When I say “alphabetical order”, I mean “alphabetical order”

#98
Por qué no los dos?

Call lexicographic order "sort by name" as it's called now, and call dumb character-by-character sort "plain" or something like that. I'm not a designer, maybe there are more intuitive names, but come on. This isn't an intractable problem.

Re: When I say “alphabetical order”, I mean “alphabetical order”

#99
post #89

Earlier quoted context omitted.

> The author wants the "worse" sort, one based on ASCII/Unicode codepoints, without any intelligence for numbers that 99% of GUI users want. I want the author's opinion on how caplital and lowercase letters should be sorted. Do they follow strict ASCII/Unicode codepoints, or do they normalize into actual alphabetical order and sort upper/lower within each letter?

And where do you sort the letter ä? (After a is correct in German, but I think Swedish does it differently.)

This feels like the right moment to mention "ch", which is considered a letter in orthodox Czech, sorted between "h" and "i". The problem is, you can't reliably distinguish between "ch"-the-letter and "ch" as just "c" and "h" combined, which are present in loan words but also some original Czech compound words.

So if you're doing it "properly", sorting strings in Czech involves understanding the etymology of every word.

Re: When I say “alphabetical order”, I mean “alphabetical order”

#100
post #81

Sorting so "foo9" is before "foo10" is called natural sort . I found out about natural sort a week ago and I am thrilled that my programs now print their output in a sensible order. Give natural sort a try and see if it improves your life too :-) I found the magic two lines of Python to do a natural sort here, by the way: https://stackoverflow.com/questions/11150239/natural-sorting...

Natural sort is an Option in sort(1):

  for i in $(seq 2 10) ; do
    touch img_$i-hn.txt
  done

  ls img_* | sort -V
  img_2-hn.txt
  img_3-hn.txt
  img_4-hn.txt
  img_5-hn.txt
  img_6-hn.txt
  img_7-hn.txt
  img_8-hn.txt
  img_9-hn.txt
  img_10-hn.txt
And we have "sort -h" to sort the output of e.g. "du -sh *" properly.

Edit: formatting and add sort -h

Post reply on HN