Throw away code

Let’s start simple. Here is a situation I have encountered more than once. We have this big long class or method, and embedded in it are several blocks of code, all commented out.

def some_method(a)
do_something(a)
calc_another

# wow
# do_do
# calc_calc
# zcalc(z)
end
What should I do? Given the code is version controlled, I would happily throw it away.

The code is commented out and will have no effect whatsoever on any program or user. Another programmer may be affected by it, though. So, make a note in the commit message :
“removed commented-out code in such-and-such method. haven’t been used in a while”
Caveats apply for very large blocks of commented-out code, or it has warnings not to remove. But these can be easily solved with some programmer-to-programmer communication.

There are other things that can be theoretically thrown away, such as:
  1. Once off experiments / prototype
  2. Quick and dirty functions
  3. Generally ugly code in the project
However, each of this has it’s own set of code, teamwork and business-related problems. Yes, there is the urge to reduce mental strain - working what does piece of code do - which leads to “let’s rewrite” moments. I would love to know what a programmer or a team can do in each of this instances. I have some ideas, but these will be topics for later discussions.

* I have always wanted to write down some of my experiences as I embark on a programming life. This is my starting contribution.