DispensablesLow

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.

Model cost, team of 8$2K-$6K/yr
Severity
2/5
CategoryDispensables
Detection4 tools

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.

Threshold: Any commented-out code block longer than 2 lines should be deleted. Any function with zero callers (verified by static analysis) should be deleted. Trust version control.

Why It Costs Money

1

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.

2

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.

3

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 SizeLowMidHigh
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.

SonarQube
squid:S1068 / squid:S1144 / squid:S125

Unused fields, unused private methods, commented-out code

CodeClimate
unused-code

Detects unreferenced functions and variables

ESLint
no-unused-vars / no-unreachable

Catches unused variables and unreachable code after returns

TypeScript
noUnusedLocals / noUnusedParameters

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.

Effort (our estimate): 5-15 minutes per block
Impact: Immediate reduction in reading burden and search noise

Enable strict compiler flags

Setting up a codebase for the first time or during a cleanup sprint

Effort (our estimate): 1-2 hours to fix all warnings
Impact: Prevents future dead code accumulation

Run coverage analysis

Identifying dead code that is not syntactically obvious

Effort (our estimate): 2-4 hours for initial analysis
Impact: Finds dead code that static analysis misses

Related Smells

Updated November 2026