Wednesday, January 7

Natural Sorting - not this chestnut again

Ah the joys of natural sorting lists... If you know what I am talking about then you'll roll your eyes instantly, but if not let me explain...!

Think of a list of items, we'll take some fictitious products as an example:

C200, C230, C2000, C55, and C5000

If you were to order these by hand, you might do something like:
  • C55
  • C200
  • C230
  • C2000
  • C5000
This would be a numerically logical sorting... smallest first

Now, without fiddling with code, a machine would order these differently.
  • C200
  • C2000
  • C230
  • C5000
  • C55
Because ascii sorts in the following order A, a, number, symbol, and 2 is smaller that 5. I quite like the way that people refer to this as Asciibetical. It's also completely nonsensical to anyone other than a programmer.

Joy... and a problem we come across every couple of years when dealing with an A-Z alpha-numeric listing. There are a few guys out there who have spent time collating, writing and generally trying to solve this issue for people, and kudos to people like Dave Koelle who have a whole set of algorithms specifically to address this.

Otherwise, its just another day having the same argument with people
'a-z is broken?'
'no thats correct sorting'
'thats not alphabetical!'
'thats how ascii displays it'
'I am not a machine'
'Stupid user!'
'Stupid developer!'

And the cycle of life continues...

No comments: