Monday, February 8, 2010

Day 24

So while driving home from work today, I drove by a house which left their garage door open. They had left their car out in the snow because their garage was so overwhelmingly packed with stuff that they no longer had room for their car. When I saw this, the two things came to mind. The first was my Grandma, who is the type of person who could never throw anything away, and as a result has no room in her garage. The second was what a program would look like if she had written it.

Often I, and many other developers I know, have the temptation to comment out some code and keep it around just in case it might come in handy later. This happens quite often when you are spiking, or when (and god knows why) you are not using version control. You write a tid-bit of code, find a better way to rewrite the code, but save the old code just in case your new idea fails. Do this over and over, and things can get pretty ugly.

I recently wrote some C and X86 assembly to write an operating system for one of my classes. My group and I really had no idea how to start going about writing our OS, so quite frequently we would save old code we had written so that we wouldn't have to reinvent the wheel. As a result, in some files we had to doing some hunting just to find the real production code through the haze of the comments. This is a Dirty Garage.

Uncle Bob uses the metaphor of a Dirty Kitchen for poorly written code. If you are a chef working at a restaurant on a very busy night, and rather than cleaning up pans or knives after every use, you instead just toss the dirty ones aside and grab the nearest clean on. At first, you will be able to get a bunch of dinners out quite rapidly, since you waste no time cleaning anything; however, as the night progresses you will find it more and more difficult to get any clean pans and eventually you virtually stop cooking all together and spend most of your time hunting down clean tools. The same thing is true with software. If you rush to get a lot done really quickly, and you push off keeping your code clean, then eventually you will hit a point where you are spending more time trying to figure out what is going on instead of developing.

If my Grandma were to write a program, I imagine that it would be so densely packed with commented and saved code, that unveiling any functionality would be quite a challenge. This is a Dirty Garage. Where you have so much saved junk in your files that you no longer have any room for that which is meant to occupy your production files, your functioning code. Where you fear deleting code because you think it might be useful again in the future. Sometimes this can be true, and if you are just messing around and trying to refactor, often commenting out code for later or for reference can be valuable. Often though, you will comment out a block, forget about it, and it will linger and rot your code. Perhaps you hand your project off to another developer who is too afraid to delete the commented code because he/she thinks it might have some unspoken value.

Although a Dirty Kitchen can be more harmful than a Dirty Garage... no one wants to park their car in a garage full of junk.

No comments:

Post a Comment