Tracker file name sort order

tracker

Does that make sense? What I’m used to:

$ ls | cat
119
1aa
999
99a
99b
9a9
a99

See Natural sort order - Wikipedia.

If this is supposed to be natural, something’s wrong with it, or wrong with me.

With a long list of files, the value of a presenting them in a sort order is that you can go to the place where the one you’re looking for should appear. Does this meet that objective? I think not.

Consider the following example.

Lexicographical order:

1 - track name.mp3
10 - track name.mp3
11 - track name.mp3
12 - track name.mp3
2 - track name.mp3
3 - track name.mp3
4 - track name.mp3
5 - track name.mp3
6 - track name.mp3
7 - track name.mp3
8 - track name.mp3
9 - track name.mp3

Natural order:

1 - track name.mp3
2 - track name.mp3
3 - track name.mp3
4 - track name.mp3
5 - track name.mp3
6 - track name.mp3
7 - track name.mp3
8 - track name.mp3
9 - track name.mp3
10 - track name.mp3
11 - track name.mp3
12 - track name.mp3
1 Like

That’s fine, but it doesn’t make the example I illustrated any better. Ironically, they’re numbers, too - hexadecimal.

When there are intermixed alphabet letters, it isn’t natural any more. Here’s a first cut at how I’d do it, using a small awk script:

$ wc sla
36 94 455 sla

$ ls tracks | sla
1 - track number 1
2 - track number 2
3 - track number 3
4 - track number 4
5 - track number 5
6 - track number 6
7 - track number 7
8 - track number 8
9 - track number 9
10 - track number 10
11 - track number 11
12 - track number 12

$ ls abc | sla
119
1aa
999
99a
99b
9a9
a99
`

… Though on review of how it works with real files, I’m done with trying to make up any sort that’s more numeric but preserves the simple predictability of lexical sort.

What I think would be the simplest work-around is to add a field that Tracker displays, that would be the same filename sorted lexically. I thought about just adding an attribute, but that’s rather error prone since it would have to be managed in an open-ended number of cases involving creation and renaming of files.

Here’s how Tracker parses it, not knowing about hexadecimal:

1 (aa)
9 (a9)
99 (a)
99 (b)
119
999

a99

I think hexadecimal numbers are unusual enough (in the average use of a computer) that it’s acceptable to not handle them. However, maybe we can make Tracker be a bit more selective in its “is this a number?” check? For example, don’t try to sort this way if there are letters and numbers together, without any space or punctuation?

That’s what I mean, though - can’t really win this way. What happens to the track list, when you add a number 3b? Should that send the whole directory to lexical order? Numeric sort everything else, and put 3b at the end, after 12? Ordinary lexical sort is better here, until the numbers get to the next order of magnitude. Etc. What happens if you have “3 - Slop Bucket 10” and “3 - Slop Bucket 5”? Etc.

There’s a fundamental, inescapable tension between predictable and natural, because it’s about what rule a person might use in a limited domain of items. That can’t really be generalized, and the harder you try to finesse it, the harder it gets to understand and predict.

I have no real interest in sorting by numeric hexadecimal value - I just appreciated the natural tendency of equal-length hexadecimal strings to come out in the same order either way.

Tracker doesn’t appear to do the right thing with Roman numeric either, by the way.