Unreachable Code
Code no input can execute — usually a guard against a state the surrounding invariants forbid.
Unreachable code cannot be executed by any input. In its obvious form it is code after a return. In its interesting form it is a guard, a fallback, or an error branch protecting against a state the surrounding design makes impossible.
Unreachable branches are worth eliminating rather than tolerating for two reasons. They are noise — a reader cannot distinguish a real constraint from a defensive reflex, which is Chesterton's Fence in miniature. And under a strict Coverage Gate they are unfixable by testing, since no test can reach them.
Some recurring generators, and their structural fixes:
- A strict compiler setting making indexed access possibly-undefined forces a guard even when the key came from the same map's own keys. Iterating over entries rather than keys removes it, because the tuple type is not optional.
- A defensive null check on a reference whose invariant guarantees it exists. A non-null assertion compiles to nothing and removes the branch.
- Independent optionals that always travel together — a URL and its alternative text — create a "one present, one absent" case that no caller can produce. Modelling them as a single both-or-neither unit deletes it.
- A default value for a parameter every caller supplies.
Each fix removes the branch rather than testing it, which is the distinction that matters.
See also5
Hand-picked in the note itself — the neighbours worth reading next.
Branch Coverage
The proportion of conditional outcomes exercised — the strictest ordinary coverage metric, and the most informative.
Testing & Verification10 connections
Defensive Default
A substituted value that papers over a missing input and hides the misconfiguration that produced it.
Method9 connections
Coverage Gate
A build check that fails when coverage falls below a threshold, and what that pressure produces.
Testing & Verification14 connections
Schema Validation
Checking data against a declared shape at runtime, and using the result as the typed value.
Agents & Language Models11 connections
Code Coverage
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
Testing & Verification12 connections
Related3
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from8
Notes elsewhere in the wiki that reach for this one.
- Branch CoverageTesting & Verification
The proportion of conditional outcomes exercised — the strictest ordinary coverage metric, and the most informative.
- Chesterton's FenceMethod
Do not remove something whose purpose you cannot explain.
- Code CoverageTesting & Verification
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
- Coverage GateTesting & Verification
A build check that fails when coverage falls below a threshold, and what that pressure produces.
- Defensive DefaultMethod
A substituted value that papers over a missing input and hides the misconfiguration that produced it.
- Fail FastMethod
Crash at the point of misconfiguration rather than degrading quietly into a wrong state.
- InstrumentationTesting & Verification
Adding measurement to code so its execution can be observed, and the distortions that introduces.
- Schema ValidationAgents & Language Models
Checking data against a declared shape at runtime, and using the result as the typed value.