Kernighan's Law
Updated 2026-07-30
Summary
Debugging is twice as hard as writing the code in the first place.
Definition
A programming aphorism attributed to Brian Kernighan says debugging is twice as hard as writing code, warning that excessively clever code makes debugging difficult. “Twice” is rhetorical, not a measured ratio valid for every program or a prescription to reserve half one’s intelligence.
Introduction
How to use
Evaluate the later costs of understanding, diagnosing, and changing an implementation. Prefer code the team can explain and test; document and measure complexity needed for performance.
Mechanism
Debugging reconstructs actual execution and its divergence from expectations. Complex control flow, hidden state, and lost context add cognitive burden. Clear structure can help, but no fixed multiplier determines debugging cost.
Practice
In progress 0/3Practice this model in one real situation:
Cases
- Hypothetical example: a compact bitwise implementation is difficult to explain. The team tests it against a straightforward version and measures performance. If the gain does not justify maintenance costs, it keeps the clearer version, without assuming a fixed number of hours saved.
Common pitfalls
- Equating 'clever' with 'good code'; thinking that as long as it runs now, it's fine; trading complexity for small performance gains.
Sources
Source support: Explicit
- lawsofsoftwareengineering.comhttps://lawsofsoftwareengineering.com/print/laws/kernighans-lawverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS