Commented-Out Code


I'm quite allergic to code that is commented out but left in the code base without any clear reason. Such dead code bloats the code base and distracts the programmer from the executable code. The main reasons why people leave commented-out code in the source are indecisiveness and temporary conditions. Indecisiveness is the more common of the two and stems from a very human characteristic that people are hard to admit failure and have problems parting ways with their belongings. In such case I first try to comfort the programmer that his code will not actually be deleted but will always be available in code repository. If that doesn't cut it I ask the programmer to augment the comment with the description why the code was commented out and when should it be deleted. Here's an example: [sourcecode language="python"]

# This code was deleted on 2013-04-12 because I'm really proud # of it and I cannot part ways with it. # If this code is not commented in by 2013-06-23, delete it! # # for element in list: # do_something(element)


I prefer adding such comments to commented-out code also for the case when code is excluded only temporarily. Knowing the reason why the code was commented-out makes the job of purging the code later much easier. And having explicit permission to delete dead code after the specified date makes cleaning the code base trivial.

Enhanced by Zemanta