March 2, 2012

Dead code evilness

Working on several projects at the same time is really exciting, you have to administer your time-sheet between tasks and work with different people. Hence the diversity, different technologies and environments.
But there is something common between all those projects, dead code. Dead code can be classified in some few categories:
  • Legacy code.
  • Refactoring-result code.
  • Patches.
It's really frustrating for someone during development to see some code like this:

  • What does the '0' mean?
  • Why is the first line still present there as commented code?
  • Is it really important to have it there?
  • Should I remove it?
  • What about the other parameters?
  • Why it was commented in first place?
  This can lead you to several problems if you don't know how to answer these questions. But then again, why would you? Wouldn't be better to have something like this?:

If it's dead code, I mean, it's already dead, it should be removed for the sake of other developers. If you are working with Revision Control Systems (and I don't know why you shouldn't), the commented code is not longer required, you can revert or reapply a patch whenever you want.

In summary, get rid of your dead code, kill it, burn it, bury it.