Live data from Hacker News

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

sebastiano.tronto.net

41–50 of 385 posts

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

#41
post #25
post #17

Earlier quoted context omitted.

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

Author here - My surprise stems exactly from the fact that for the last few years I have exclusively managed my files via a the UNIX shell, which behaves in the classical way.

When I started using Linux as my daily driver after many years of Windows (but with familiarity with UNIX systems going way back), I knew it would be like that in the terminal, but it still took some adjustment. But actually, Nemo does the same "natural sort" thing, and also sorts case-insensitively.

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

#43
post #42

I think the algorithm is probably incorrect. A number starting with 0 should be treated lexically not numerically. Otherwise you have a situation where img_1_01.jpg and img_01_1.jpg does not have a complete ordering.

It wouldn't be the first time widely-used software sorted numbers by a function that does not produce a total ordering. For example, Excel: https://gregat.es/excel-numeric-order-transitivity/

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

#44
post #36

Earlier quoted context omitted.

You mean file9 before file10? I have some beef with microsoft, that you can only change this at the Computer level, not per user (see registry key below). Also they call it natural sorting for users, but logical sorting internaly. Unify your termini! [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoStrCmpLogical"=dword:00000001

To change it per user, set it in the user's hive instead of in the local machine hive (e.g. HKEY_CURRENT_USER instead of HKEY_LOCAL_MACHINE)

TIL they are called "hives". Windows Registry is an interesting thing. Even casual users have to interactive with it once or twice w/o fully understand it.

https://learn.microsoft.com/en-us/windows/win32/sysinfo/regi...

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

#45

Digits and any other characters that are not A-Z and a-z should not get sorted. That's the true result of doing what you asked and not what you meant. Pedantic, but that's why we are here.

  > Digits and any other characters that are not A-Z and a-z should not get sorted.
Do you suggest that sorting in any language other than English should be broken?

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

#46

I thought this was pretty well known. E.g. the macOS Foundation library even exposes NSString.localizedStandardCompare() [1] which implements the sorting algorithm used by Finder, and should be used by any well-behaved macOS application. Windows uses StrCompareLogical [2]. [1] https://developer.apple.com/documentation/foundation/nsstrin... :) [2] https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/...

I would have assumed it worked the same as ls, so I found the article interesting. But now that I know, I think this way is better.

I can’t think of any case where I would need purely alphabetical sort. In most photo browsing apps, photos will be sorted by timestamp rather than filename. If I really needed it to sort properly in file explorer, I would try sorting on created date. And failing that I would probably just normalize the file names.

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

#48
post #39

To answer the question in the article, I’m pretty sure Windows Explorer (and probably File Manager before that) has sorted filenames this way for at least 30 years.

I can confirm that this does not happen in Windows 98, but does happen in Windows XP.

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

#49
I got used to naming files/folders with leading zeros when I want them to be sorted alphabetically (for example payslips/invoices, etc).

But I'm a tech guy, I know what does "alphabetically" mean in the tech world. And it probably is not what common folks mean when they think "alphabetically" outside the tech world.

Edit: in fact, if I recall correctly, the proper term for this kind of sort (the one OP wants) is alphanumeric sort.

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

#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.

Post reply on HN