I’m a big fan of Jeff Atwood’s “Coding Horror” blog – and I’m certainly not alone in that respect! A recent entry “Sorting for humans” talks about how the default sorting algorithm that most programmers use for sorting text doesn’t lead to a “natural” sort order. When sorting Alpha-numeric entries, you end up with an apparently illogical jumbled order – where “z10″ appears after “z1″ but before “z2″.
Anyone who knows anything about ASCII charts (and Unicode ordering!) will recognise what’s going on. For those of you who don’t, have a look at Wikipedia’s entry on ASCII character encoding.
I read through the comments on this particular blog entry, expecting to find some clever ideas for “natural sorting” algorithms. – At this point in time, I don’t need one, call it part of my “Professional Development“. Whilst there were a few implementations with good ideas, the thing that struck me were comments like this:
I’m sorry, but I don’t agree. Let’s call it alphanumerical.
z100 should always go BEFORE z2, the same way that table goes before tar.
Also, anyone naming their files *name*-*number* and not putting in the extra digits should not order by name, but by date.
And I take offense at Kate Rhodes’ comments. It’s yet another case of stupid users.
This admittedly, was the harshest comment I saw and you’ll be pleased to note that there were other commenters politely suggesting that an attitude adjustment may be in order. But the sentiment (that the “strange” ordering was correct) was echoed several times by other commenters. I’m not saying there weren’t valid points listed in their objections – some commenters noted that Internationalisation (I18n) made the task of natural sorting more difficult. What I am saying is it’s not good enough to justify your approach and think the matter is resolved.
I’ve programmed for long enough to remember times when I thought differently to users. – I still do at times. I also know that I can be a persuasive arguer. Programmers using their logic skills can be like that… But, no matter how logical or compelling my argument is, if it’s not what the user was expecting, it’s called “a bug”. If (or when) this happens to you, swallow your pride and alter the program. Either make it behave the way people are expecting it to, or make it such that users are expecting it to behave the way it does.