Dead Code: What It Costs and How to Fix It
Code that is never executed: unreachable branches, unused variables, commented-out blocks, and orphaned functions.
What It Is
Dead Code is any code that is never executed at runtime. This includes unreachable branches after an early return, unused functions and classes, commented-out code blocks left 'just in case,' and variables that are assigned but never read. Dead Code accumulates gradually as features are removed, requirements change, and refactoring is incomplete. It is the easiest smell to detect (most static analysis tools catch it automatically) and the easiest to fix (delete it), yet it persists in most codebases because developers are afraid to remove code they did not write.
Why It Costs Money
Reading burden is the primary cost. Every developer who navigates through a file with dead code must spend cognitive effort determining whether the code is live or dead. Commented-out blocks are particularly expensive because they suggest someone wanted to keep the code, making developers hesitant to delete it.
False positives in search results. When searching for usages of a function or variable, dead code appears in results, slowing down investigation. Developers must check each result to determine if it is live code or dead.
Build and test time inflates. Dead code that compiles but is unreachable still adds to compilation time, test coverage gaps, and code complexity metrics.
Specific Cost Mechanisms
- ●Reading overhead: time spent reading code that never runs
- ●Search result noise: dead code shows up in every search and has to be read and ruled out
- ●False sense of test coverage: unreachable code counted in coverage metrics obscures actual coverage
Estimated Annual Cost
Cost of one instance a year by team size, from our model at $180K fully-loaded cost per engineer. Low and high use the bottom and top of the Low inputs; mid is halfway. See full methodology.
| Team Size | Low | Mid | High |
|---|---|---|---|
| 3 devs | $700 | $2K | $3K |
| 5 devs | $1K | $3K | $4K |
| 8 devs | $2K | $4K | $6K |
| 10 devs | $2K | $5K | $7K |
| 20 devs | $5K | $9K | $14K |
These are model outputs, not measurements. Every input is on the cost model page, and the same model produces the figures on the 22 smells page. Put in your own team and cost in the smell profile calculator.
How to Detect It
Specific rules and thresholds for automated detection. See full tool comparison.
Unused fields, unused private methods, commented-out code
Detects unreferenced functions and variables
Catches unused variables and unreachable code after returns
Compiler flags for unused declarations
Refactoring Patterns
Proven techniques to eliminate this smell. See all refactoring patterns.
Delete and trust version control
Always. Dead code can always be retrieved from git if needed.
Enable strict compiler flags
Setting up a codebase for the first time or during a cleanup sprint
Run coverage analysis
Identifying dead code that is not syntactically obvious