Thursday, 9 August 2007

Is all code created equal?

Almost every other day, I go home with a WTF story after dealing with our legacy code. Now, I'm a realist (I like to think) and accept that if I reviewed code I wrote 12 months ago, I would be unimpressed. The thing is that the feelings stoked by the current code and design include outrage, disbelief and once in a while hysterical laughter.

Today I'm stopping to ask myself if I've just become a code snob and the code isn't really that bad.

Should I just accept it and pretend it's easy to work around? Do I actually want to rewrite every line of code in the world? Is it fair to expect developers to pick the bandaids of the old code and fix it? Is all code created equal?


Giles said...

I've been through this a lot. I know the feeling: "Surely all this code can't be that bad, it compiles, it works. Am I just being overly critical?" I get those thoughts when all the code I've seen for an extended period just seems to really, really suck.

The thing is software development is hard; good programmers are really rare. Otherwise very intelligent people who may be extremely proficient in other areas of computing, such as chip design can be really godawful software engineers.

Doesn't stop you from feeling overly judgemental though.

There's the concept of 'yet another broken window.' Broken windows always need to be fixed. You're not being overly judgemental, if it looks broken then it's time to fix it.

Saying, it gets by, not how I would have done it but passable just leads to all the code sucking.

Adam said...

I know that you should fix code if you have time. I'm learning that the bet thing for rewriting bad code is to have a test harness around it. That's a wonderful safety net although the safety net probably took twice as long as the code to write.
I found some code yesterday that used a call to a database to compare 2 dates and return the latest... how about that for a WTF moment. Somebody just didn't want to write a class to handle the date.... or a helper function to parse the date.... or just anything sane at all.