Throw Away Code
by Jeremy on Jul.09, 2008, under Uncategorized
I was reading today and came across something that seemed contradictory to what I’ve learned over the years. At the same time, it just made a lot of sense.
Programmers don’t throw away code enough. When faced with a hunk of code someone else wrote, which doesn’t appear to be quite right, or is misbehaving, the proper action is to figure out what it’s supposed to do, and its interface, and then scrap it and start from scratch. (I’m not talking about rewriting whole programs here, just sections.) Instead, people try to handle the corner cases, or hunt down where the leak is. Just stop, think for a little while, get the structure well posed, then write that.
We were bit by this problem at OV recently. Instead of trashing pieces that were there in order to make them work, and writing them based on the original specification, we attempted to bend them into place in order to “save time”. Needless to say, that didn’t work out so well. Not only did we not save time, we used up too much.
Next time, I think it would be more appropriate to go with my gut feeling. Instead of trying to bend the immalleable, we should strive to replace the pieces. Sometimes code is just so bad that it’s not smart, safe, or sane to leave it in place.
I’m certainly losing my sanity, about now.