Live data from Hacker News

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

sebastiano.tronto.net

11–20 of 385 posts

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

#11
When you get a bunch of files (let's say 1000+) without leading zeroes, this is a blessing. But I get the author's frustration, the expected behavior is not there, instead, he gets magical sorting that is wrong for his use case. I'm not sure what the ux should be, and maybe the algorithm here could be smarter, but it's a trade-off.

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

#12
post #4

If I understand the article, the author wants magic :) I take it to mean they want the system to know file_9.txt is less then file_10.txt. I never saw that happen in any OS, so I do not know what he is referring to. Maybe whatever that old system was, it sorted by create time as opposed to file name. So, the author can try and create "aisort" that will look at all file names and add leading zeros to the file numeric…

Nope, you got it completely reversed.

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

#13
post #4

If I understand the article, the author wants magic :) I take it to mean they want the system to know file_9.txt is less then file_10.txt. I never saw that happen in any OS, so I do not know what he is referring to. Maybe whatever that old system was, it sorted by create time as opposed to file name. So, the author can try and create "aisort" that will look at all file names and add leading zeros to the file numeric…

>I take it to mean they want the system to know file_9.txt is less then file_10.txt.

The polar opposite, actually.

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

#14
post #4

If I understand the article, the author wants magic :) I take it to mean they want the system to know file_9.txt is less then file_10.txt. I never saw that happen in any OS, so I do not know what he is referring to. Maybe whatever that old system was, it sorted by create time as opposed to file name. So, the author can try and create "aisort" that will look at all file names and add leading zeros to the file numeric…

It’s not magic. It’s called natural sort and it doesn’t require gobs of memory. Most (all?) modern OS file managers will natural sort on file names.

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

#15
post #9

"I created the Alphanum Algorithm to solve this problem. The Alphanum Algorithm sorts strings containing a mix of letters and numbers. Given strings of mixed characters and numbers, it sorts the numbers in value order, while sorting the non-numbers in ASCII order. The end result is a natural sorting order." https://web.archive.org/web/20210207124255/http://www.daveko...

There are many older instances of that, such as "versionsort" from various Linux tools and libraries. I think this has likely been independently recreated several times, with various subtle differences.

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

#16
post #10
post #2

https://www.unicode.org/reports/tr10/#Contextual_Sensitivity : “There are additional complications in certain languages, where the comparison is context sensitive and depends on more than just single characters compared directly against one another, […] Numbers. A customization may be desired to allow sorting numbers in numeric order. If strings including numbers are merely sorted alphabetically, the string “A-10” co…

But -10 is smaller than -2, right?

Filenames rarely have negative numbers in them, and it'd usually be ambiguous whether they were negative or dash-separated positive.

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

#17
post #4

If I understand the article, the author wants magic :) I take it to mean they want the system to know file_9.txt is less then file_10.txt. I never saw that happen in any OS, so I do not know what he is referring to. Maybe whatever that old system was, it sorted by create time as opposed to file name. So, the author can try and create "aisort" that will look at all file names and add leading zeros to the file numeric…

No the author is saying the opposite. They expect file9.txt to be after file10.txt, but it many modern operating systems, it isn’t!

Really, I do not know how I missed that :) I read it a couple of times to and I still thought he wanted it the other way.

So my original comment kind of stands but in a opposite way.

I have never see file_9.txt sorted before file_10.txt, I just tested it on OpenBSD and I got this, which I have always seen:

$ ls|sort

file_1.txt

file_10.txt

file_12.txt

file_2.txt

file_20.txt

file_3.txt

file_9.txt

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

#18
post #4

If I understand the article, the author wants magic :) I take it to mean they want the system to know file_9.txt is less then file_10.txt. I never saw that happen in any OS, so I do not know what he is referring to. Maybe whatever that old system was, it sorted by create time as opposed to file name. So, the author can try and create "aisort" that will look at all file names and add leading zeros to the file numeric…

>I take it to mean they want the system to know file_9.txt is less then file_10.txt. The polar opposite, actually.

[deleted]

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

#19
I get it, but if all these major operating systems are handling this same ambiguous [0] situation in the same way, perhaps one needs to reevaluate their mental model or expectations.

Am I out of touch? No, it's the operating systems who are wrong

0 - numbers are not part of the alphabet.

Post reply on HN