MrKWatkins

The Order Of Things

Code that relies on the order of things generally annoys me. It tends to be weak, fragile code because someone somewhere will come along and change the order. Most of the time nothing to bad will happen. Names in a drop down will no longer be alphabetical, that sort of thing. But I've seen code 'oh crap yellow screen of death' break due to people relying on the order of data. The code they'd written depended on the order of items coming out of the database, however they didn't have an ORDER BY clause in their SQL. So one day someone inserted a record in the table, the data came back differently, their code couldn't handled that and a lovely NullReferenceException graced the front page of the website. Not good. If your code must depend on order then your code should make sure things are in order!

I found order behaviour in the wild yesterday, in the RSS Best Practices Profile. Whilst using the W3C's Feed Validator to check the markup of this site's RSS was up to scratch I came across the recommendation that 'all item elements should appear after all of the other elements in a channel.' Why? Perhaps it can be used as an optimisation for some RSS parsers, although if that's the case it should probably be compulsory rather than a recommendation because then something will depend on that fact and possibly break if that isn't the case in some feed. The only valid reason I can think of is that it makes reader the XML by hand slightly easier. If anyone knows the real answer please drop me a line; it's annoying the hell out of me...