November 11, 2008

What's with the title?

Recently, a colleague of mine has been persistently harassing me to start a blog. I secretly think it’s so that he can spare himself much of the leg work I’ve already done… after much resistance, I've finally caved and succumbed to the blogosphere... I hate that term almost as much as "Google it!"...

I have spent countless hours trawling through the many disparate corners of the internet, attempting to understand various concepts and paradigms as they’re introduced into .NET. So often, the examples I find are poorly coded and have even worse descriptions. This is my attempt to give back to the programming community and demonstrate that these examples can be simple to understand when explained properly. So here, I will deliberate on the trials and tribulations of my own .NET insights, inadequacies and musings and try and collate all my thoughts and understandings on various topics in a single place so that others won’t be destined to repeat the same work that I have.


Some time ago – it feels like a lifetime ago now, but it can’t have been much earlier than last year… I needed to do something that programmers have been doing since the dawn of programming; something we do on every trip to the grocery store - search for matching items in a list. Before I even started typing, I wondered if there’s something more elegant than looping over the list a la for…each. Enter stage left the List.FindAll() method which looks like it should do this – and it does. But it does so using a concept which at the time was alien to me – predicates (which are the subject of my next article).

A quick search on the MSDN website for List.FindAll will bring you across an article attempting to demonstrate this concept ( – which as far as I’m concerned deserves eternal recognition on Jeff Atwood’s Coding Horror website ( To this day I cannot comprehend why anything as mundane as finding items in a list would end with an example so poorly conceived that while it demonstrates the concept, is a leap to understand and promotes a coding practice so poor that it should horrify even the most novice programmer.

In the example we are provided with a method called “EndsWithSaurus” which… wait for it… tests whether or not a string ends with “saurus”… imaginative eh? The fact that the search term is a hard coded method still astounds me…

Don’t hard code anything that could be variable!

That such a basic tenet of programming has been blatantly ignored by such a major player in this industry is abhorrent in my eyes. Now any time I come across examples that promote such bad coding practices, I can’t help but think “ends with saurus” and chuckle to myself…

No comments:

Post a Comment