Live data from Hacker News

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

sebastiano.tronto.net

211–220 of 385 posts

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

#211
post #175

ls sorts filenames strictly lexicographically, comparing character by character, so e.g. "055436307" is compared as the characters "0", "5", "5", etc. so it sorts before "121134" because "0" is less than "1". if all compared characters match and one string ends, the shorter one comes first. Symbols like _ are just more characters, and their position relative to digits depends on the locale’s collation table. Google D…

It feels like this algorithm could be improved though. If a number has leading zeros you probably don't want to sort it numerically. That said the author's situation where it's numerical and different lengths seems likely rare enough that it probably isn't worth complicating things.

The leading zero isn't an issue because it will sort correctly under both systems. The issue OP is having is that he's adding random numbers after the hhmmss section. If instead he added a delimiter before the random number the files would sort correctly under both systems as well, e.g. hhmmss_num.

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

#212
post #143

Earlier quoted context omitted.

The sort rules are simple (1). Treat any consecutive sequence of digits as a number when sorting. So for example version numbers (which must be massively more common than decimals in filenames) work correctly, and 5.9 is indeed smaller than 5.10 and the latter is not identical to 5.1 . Given that this idea goes back more than two decades, has been the default behaviour of the most used OSes for many years, with no ma…

> The sort rules are simple In considering the simplicity of the rule, I think you're using a developers perspective here where we automatically classify numbers and have a clear mental model of the separation between value and representation. But I'm not sure how simple it would be to explain to a non-technical user why size_5, size_10 and size_15 are in order but size_0.25, size_0.5 and size_0.75 are out-of-order.…

> I'm regularly amazed at how little non-developer/technical users complain about strange and confusing behavior.

Because EVERYTHING a computer does to non-developer/technical users is "strange and confusing". With few exceptions, most people have no idea why their computer does something the way it does, or how they could make it do something different even if they wanted it to. And most of the time, when they complain about it to someone knowledgeable the answer will be some variant on "that's just sort of the way it is". Imagine a world where the names are sorting the way that the OP is looking for, you're still having to explain to someone why the first group sorts "out of order" and the second group sorts "in order". And if they complained, they would almost certainly get an answer that is some variant on "that's just sort of the way it is".

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

#213
post #143

Earlier quoted context omitted.

> The sort rules are simple In considering the simplicity of the rule, I think you're using a developers perspective here where we automatically classify numbers and have a clear mental model of the separation between value and representation. But I'm not sure how simple it would be to explain to a non-technical user why size_5, size_10 and size_15 are in order but size_0.25, size_0.5 and size_0.75 are out-of-order.…

> I'm regularly amazed at how little non-developer/technical users complain about strange and confusing behavior. I am a highly technical user that works with a lot of people with traditional engineering degrees but little to no software experience (except as frequent users). The answer here is that they've learned that all computer software is arcane and mysterious, and so they just accept that there will be strange…

    > traditional engineering degrees
What does that mean? What disciplines? I cannot believe that all junior graduates in engineering disciplines in the 2020s are not doing some programming, even if just writing macros in a CAD program.

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

#214

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…

Haven't people started calling this "natural" order or something?

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

#215

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…

I agree with you, but I also agree with the author: the heuristic used to figure out the "natural" ordering here is broken; if you're going to "guess" at how to order things, you need to be more sophisticated than just "find a suffix that looks like a number and order by it".

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

#216
post #60

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…

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…

> If the answer is no to any of these questions, it's likely to lead to surprise/confusion.

Worse, if the answer is yes to any of these questions, it's also likely to lead to surprise/confusion. The only way to win is not to play.

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

#217

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…

[flagged]

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

#218
post #60

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…

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…

There is a standard algorithm - CLDR collation. There are several options available but, generally speaking, it’s a standard.

The specific option for numeric sorting is “kn”.

As far as I can tell, every operating system and many other interfaces tend to use this standard algorithm.

https://www.unicode.org/reports/tr35/tr35-collation.html#CLD...

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

#219

The so-called "natural" sort makes sense for version numbers and enumeration (without zero-padding) but I'm more often dealing with file names with a datetime (like in the article), a hexadecimal hash, or just randomized string of characters that includes numbers. In those cases "natural" sort makes it harder to find the file you're looking for. Even when files are enumerated it's pretty rare to have more than 9 part…

> a hexadecimal hash

I agree with you on this point.

> a datetime

AFAICT, natural sort shouldn't ever make datetimes harder to find, unless they are formatted inconsistently, as in the author's case. Suppose one camera wrote dates as 20250928 and another as 2025-09-28. ASCIIbetical sort would do nothing to help here.

Natural sort can even improve things over ASCII sort, for instance if someone is stuck with a format like "28/9/2025" or "September 2 2025"

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

#220

Earlier quoted context omitted.

> I'm regularly amazed at how little non-developer/technical users complain about strange and confusing behavior. I am a highly technical user that works with a lot of people with traditional engineering degrees but little to no software experience (except as frequent users). The answer here is that they've learned that all computer software is arcane and mysterious, and so they just accept that there will be strange…

> traditional engineering degrees What does that mean? What disciplines? I cannot believe that all junior graduates in engineering disciplines in the 2020s are not doing some programming, even if just writing macros in a CAD program.

Most of the people I work with are 35+, but even the juniors in MechE, Aero, etc. tend to have some scripting experience that doesn't necessarily translate to having a robust intuition about DBs, the relationship between frontend and backend design, etc.
Post reply on HN