Code Smell 09 - Dead Code

Code Smell 09 - Dead Code

Maxi Contieri
·Oct 28, 2020·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Code that is no longer used or needed.

TL;DR: Do not keep code "just in case I need it".

Problems

  • Maintainability

Solutions

  • Remove the code
  • KISS

Examples

  • Gold plating code or Yagni code.

Exceptions

  • Avoid metaprogramming. When used, it is very difficult to find references to the code.

Sample Code

Wrong

class Robot {   
  walk(){
    //...
    }
  serialize(){
    //..  
  }
  persistOnDatabase(database){
    //..  
  }
}
class Robot {   
  walk(){
    //...
    }  
}

Detection

Coverage tools can find dead code (uncovered) if you have a great suite of tests.

Tags

  • Unnecessary

Conclusion

Remove dead code for simplicity. If you are uncertain of your code, you can temporarily disable it using Feature Toggle. Removing code is always more rewarding than adding.

More info

Credits

Photo by Ray Shrewsberry on Pixabay


This article is part of the CodeSmell Series.

Last update: 2021/06/11

 
Share this

Impressum

Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)maximilianocontieri.com