Skip to content

Latest commit

 

History

History
90 lines (56 loc) · 2.12 KB

File metadata and controls

90 lines (56 loc) · 2.12 KB

Code Smell 09 - Dead Code

Code Smell 09 - Dead Code

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.

Sample Code

Wrong

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

Right

class Robot {   
  walk() {
    // ...
    }  
}

Detection

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

Exceptions

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

Laziness I - Metaprogramming

Relations

Code Smell 54 - Anchor Boats

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

Laziness I - Metaprogramming

Credits

Photo by Ray Shrewsberry on Pixabay


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code