Tuesday, February 08, 2005

Don't leave commented out code in your source!

Quite often while digging through code I'll run across blocks of code commented out. Usually I have no idea why it was commented out, nor why it was left there. Regardless, whenever I see it, I immediately remove it. Source code with blocks of unused code is a huge sign of code rot.

I think many developers get in the habit of commenting out code because they think they might need it later. Or worse... aren't entirely sure of their changes and don't want to lose the original. If their solution seems to work, they release the code and expect that they'll probably come back to it if people report problems.

Don't do it! As soon as you've tested your code (you are testing, aren't you?) remove the commented out code. Your SCM is your back up. With a good SCM (Eclipse + CVS for example) and an IDE with "Local History" (did I mention Eclipse? ) you can always recover old code.

1 Comments:

Blogger Randino said...

FWIW the I think that using a good SCM system is far more important. What's really a telling sign of code rot is checking the history of a file. If you're at the end of release cycle and a file hasn't been touched is there a good reason for it? The "just get it working" mindset is what is responible for most of this kind of stuff. "I got it working so don't ever touch it again." Is an all to common approach to software development today.

5:15 PM  

Post a Comment

<< Home