TidBITS#364   19970203
 MailBITS/03-Feb-97 HTMLbits: Following up on Free Placement The Natural Order of Things CopyPaste: A Scoffer No More Palimpsest 1.1 - Is There a Document in the House? Foot Notes

## The Natural Order of Things

Here's a silly question. Are the digits between one and nine represented by a single character, or by a string of characters? In other words, when you type the number one in a filename, do you always prefix it with a zero? In all likelihood, a number of people are nodding their heads and thinking, "But of course I do that, otherwise files with numbers in the names don't sort right."

We fought with this problem with TidBITS in our early years, because although I was clever enough to prefix my single digits with a zero to pad them into double-digit numbers, I never imagined that TidBITS would be around long enough to hit TidBITS-100, necessitating a mass renaming of the first 99 issues to include an additional leading zero to pad everything into triple-digit numbers. And even today, we can't imagine that we'll be doing TidBITS long enough to need to go to quadruple-digit numbers (although stranger things have happened).

In case you're still wondering what I'm blathering about, here's an example. Assume you keep your own collection of TidBITS around, but for some reason, you rename them with more natural names. You might have the following problem with the first 12 issues when viewing them in the Finder.

```TidBITS-1.html
TidBITS-10.html
TidBITS-11.html
TidBITS-12.html
TidBITS-2.html
TidBITS-3.html
TidBITS-4.html
TidBITS-5.html
TidBITS-6.html
TidBITS-7.html
TidBITS-8.html
TidBITS-9.html
```

The trouble should be obvious - why do issues 10, 11, and 12 sort before issue 2? It's because the Macintosh System is messed up, that's why. Basically, way back when, someone at Apple decided to implement sorting the same way that Unix, DOS, and everything else does, by comparing one character at a time, instead of taking into account the fact that numbers don't sort in alphabetical order the way words do.

For years, the universal solution has been to prefix single-digit numbers with a zero, so they sort before double-digit numbers. As the number of digits increase, so must the number of padding zeroes. Computers should fit the way humans work and think. Instead, when it comes to sorting, humans must fit the way computers work.

No longer. Stuart Cheshire <cheshire@cs.stanford.edu>, author of the popular network tank game Bolo, has released a tiny freeware extension called Natural Order that overrides how the System sorts numeric parts of strings. I won't repeat the example list above, but once you install Natural Order (drop it in your Extensions folder and reboot), issues 10, 11, and 12 would sort properly to the bottom of the list.

Programs that benefit from Natural Order immediately include the Finder (for "View by Name" windows), Standard File Dialogs (in any application), and the Chooser (for sorting lists of zones, servers, and so on). However, Natural Order works by overriding the System's built-in string comparison routines and only benefits programs that call those routines. A number of programs implement their own sorting mechanisms, so those programs don't benefit from Natural Order. A few recent programs (including Anarchie 2.0 and Fetch 3.0.2 and later) include Natural Order's sorting routines internally so they sort sensibly even without Natural Order installed.

Stuart wants to hear about any programs that do not benefit from Natural Order's sorting routines, so he can try to convince the programmers of the benefit of making their programs call the System's built-in string comparison routines (and thus take advantage of Natural Order).

So, if you're bothered by the way the Mac sorts numeric strings, give Natural Order a try. You probably won't even notice it until you see a folder containing numbered files.

<ftp://mirror.aol.com/pub/info-mac/gui/natural-order-11.hqx>
<http://rescomp.stanford.edu/~cheshire/NaturalOrder.html>