Monday, October 27, 2008

algae and mold

After years of thinking that comments were desirable and made the intent of code clearer, even self-documenting, I was converted to the opposite belief after pair programming with some folks at a job interview. They were really agile, pushing XP to extremes that I had never imagined practical or possible. This breathed new life into my career, and I started to need words to describe the patterns I began to recognize.

Algae is something that distracts me from the real source code... in many editors it will be green (like the real micro-organism) or gray. In general, algae is a comment. However, at certain times I consider log/trace lines algae, as well as error handlers. If I can refactor my way away from these executable distractions, I will.

Mold is even worse. Most editors still display this code in the normal black font because it is potentially executable, but in fact it is unreachable code due to some poor refactoring in the past. Whenever I find mold I am happy to delete it.

Algae and mold promote code rot. They tend to grow and fester all by themselves. For example, a dead patch of code shows up as a consumer of some object that also is not used--so a programmer erroneously thinks an object can't be removed from the system. Or someone sees a comment they don't understand, and instead of deleting it, they code around it. Maybe that means they sprout a method to get away from the confusing comment, or they add more comments to describe the part of it they do understand. Regardless, the version control system will always remember what that comment used to say. Extract a method using the comment as the new function's name, then just delete the algae!

No comments: