Useless code

How would you respond to useless code?

You come across a line of code that’s obviously wrong, and has no effect at all. It’s been running in production for 5 years.

Or if you’re not a developer, imagine one of the developers you work with comes across this situation, and they ask for your advice.

Let’s say the code looks like:

x = x

It’s assigning a value to itself. Assume this is a language where such an operation has no side effects. It’s just an obvious mistake. It’s even more useless than one of those novelty useless machines that serves only to turn itself off when turned on…

How would you react, or advise your developer colleague to react? And why? (I’ll give my answer next week.)

  1. Ignore the non-functional code and move along.
  2. Delete the non-functional code.
  3. Read the surrounding code, perhaps the output of git blame to try to undertstand the intention, and fix it.
  4. Something else.
Share this