Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M0037

Kernighan's Law

Kernighan's Law
BusinessmediumManagement
Included
account_tree

Updated 2026-07-30

Loading revision record…

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.

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/3

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

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

account_treeGenealogyexpand_more

RELATED MODELS