Dead Code — Code Smells Catalog Skip to content

Dead Code

Dispensables Unnecessary Complexity Code Smell Between Class

You read past it wondering if it's safe to delete. Unreachable branches, commented-out blocks, functions that last ran in 2019. They cost nothing at runtime but tax every developer who encounters...

1 min read 1 source

Overview

If part of the code is not executed, it is a Dead Code. This code smell includes any place that the code executor will never reach, including the code that was commented out. Any if or case condition that cannot be reached, any code in methods and functions after the final return statement, or any code inside a try except/catch block that will never throw an error. [1] This usually is not that easy to detect and requires tool assistance. [2]

Causation

Never refactored long else-if blocks eventually have so many paths that no one even remembers if they are accessed anymore. Perhaps a new way of working was introduced, and the old code was never cleaned up.

Problems

You Ain't Gonna Need It Principle Violation

Old code that was not deleted but commented out "just-in-case" is just bloating the codebase.

Refactoring

  • Remove It

Sources

Browse All 56 Smells