Live data from Hacker News

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

sebastiano.tronto.net

281–290 of 385 posts

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

#281
I am surprised how many people are comfortable calling sorting numbers alphabetical sorting (including TFA).

In true alphabetical sorting, sorting numbers is undefined behaviour. Both of these sorting methods are valid extensions of alphabetical sorting, and which you prefer is just that: a preference.

So actually when he says ‘alphabetical order’, he does not, in fact, mean ‘alphabetical order’.

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

#283

Earlier quoted context omitted.

> Display strings in a consistent, documented, manner. IMO, "Treat any sequence of digits as a number for the purpose of sorting" is consistent. I'm not sure if it's documented—I've never needed to look up the documentation—but if it's not, the developers could certainly fix that. > this is your preference for a specific situation. Sure, but we generally make decisions based on which situations we think will be most…

Do I understand that you want these to be sorted like this? 1 2 9 10 11 So I guess you also want things sorted like 1.1 1.2 2 9 9.9 And also 1 1.1 1.10 1.2 1.10.1 So when you're done defining whatever crazy rules you think up, how do I pause whatever and edit the filenames to get them back into lexicographical order? You can massage lexicographical to meet your needs. I can't massage your arbitrary rules to meet my n…

Your examples don’t need any extra rules to be sorted correctly. The basic idea is that any sequence of digits is treated for sorting as if it were a single character. On my iPhone, your examples are sorted as expected.

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

#284

Earlier quoted context omitted.

> Display strings in a consistent, documented, manner. IMO, "Treat any sequence of digits as a number for the purpose of sorting" is consistent. I'm not sure if it's documented—I've never needed to look up the documentation—but if it's not, the developers could certainly fix that. > this is your preference for a specific situation. Sure, but we generally make decisions based on which situations we think will be most…

> IMO, "Treat any sequence of digits as a number for the purpose of sorting" is consistent. Are you sure about that? So how do you suggest handling hexadecimal numbers? Or octal numbers? What about binary numbers? What about file names with portions of a date and/or time? How is a program supposed to know any of the above? > Let's say I have a directory of 32 numbered files. Assuming any of the filesystems I am aware…

Okay, I'll refine the rule to "Treat any sequence of digits as a base 10 whole number for the purpose of sorting". I still think this is quite clear. (Frankly, I also think the original definition is quite clear unless you're purposefully trying to misinterpret it.)

> those names are strings having one or two characters. They are not "numbered files."

Yes they are! In this context, a number is an idea, not a data type. Strings are capable of containing numbers.

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

#286
Historically I'd like to add that FileNames are just sequences of bytes that come with a few restrictions.

They don't even have an encoding you can use to sort something. Windows FileNames look like UTF-16, but they can be truncated. You can't convert them to UTF-8 and back without loss. (For that you need WTF-8)

Once you use random FileNames you'll start to notice...

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

#287

Earlier quoted context omitted.

> Display strings in a consistent, documented, manner. IMO, "Treat any sequence of digits as a number for the purpose of sorting" is consistent. I'm not sure if it's documented—I've never needed to look up the documentation—but if it's not, the developers could certainly fix that. > this is your preference for a specific situation. Sure, but we generally make decisions based on which situations we think will be most…

> IMO, "Treat any sequence of digits as a number for the purpose of sorting" is consistent. Are you sure about that? So how do you suggest handling hexadecimal numbers? Or octal numbers? What about binary numbers? What about file names with portions of a date and/or time? How is a program supposed to know any of the above? > Let's say I have a directory of 32 numbered files. Assuming any of the filesystems I am aware…

Octal or binary numbers are going to be fine, but it'll totally and confusingly mess up hexadecimal numbers.

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

#288
post #272

Earlier quoted context omitted.

> 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 no such thing as natural Yeah, but there is such a thing as "give a predictable and consistent way I can…

Budget 2025-09.ods and Budget 2025-10.ods would sort reliably. The options explode infinitely if you start trying to guess what people want in terms of semantic grouping. One user might want to see "September Budget" beside "September Sales Projections" and "September Calendar", and another might want to group it with "October Budget" and "November Budget". If you have simple, stupid, but predictable tools, people ca…

There is a simple criteria for ordering file names: treat sequences of characters as alphabetical, and sequences of digits as numbers.

It's easy to understand and predictable; it just happens to not be based on ASCII character codes, which is a legacy technology method only ever meaningful to US developers.

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

#289
post #94

Earlier quoted context omitted.

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.

That's not fractional though.

Proper fractional, 1.11 is smaller than 1.3.

In versions, 1.11 is larger than 1.3

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

#290

Earlier quoted context omitted.

> IMO, "Treat any sequence of digits as a number for the purpose of sorting" is consistent. Are you sure about that? So how do you suggest handling hexadecimal numbers? Or octal numbers? What about binary numbers? What about file names with portions of a date and/or time? How is a program supposed to know any of the above? > Let's say I have a directory of 32 numbered files. Assuming any of the filesystems I am aware…

Okay, I'll refine the rule to "Treat any sequence of digits as a base 10 whole number for the purpose of sorting". I still think this is quite clear. (Frankly, I also think the original definition is quite clear unless you're purposefully trying to misinterpret it.) > those names are strings having one or two characters. They are not "numbered files." Yes they are! In this context, a number is an idea, not a data typ…

I generally agree that treating substrings that are numbers as numbers is a good default for most users in most situations.

However, for hex numbers this simply won't give good results because some of them will just happen to not contain any of the digits A to F and be treated as base-10 numbers by the heuristic while others will include these digits and be sorted differently.

(So, a having a strict lexicographic mode as an alternative in file managers would be nice.)

Post reply on HN