Programming by Coincidence

Categories
Design
Sources
The Pragmatic Programmer

Relying on code that happens to work without understanding why, building on undocumented behavior, lucky timing, or side effects you never verified. The opposite is programming deliberately: knowing why each part works and what it depends on.

Why it Matters

Code that works by accident is a trap. It rests on assumptions that were never true or were only incidentally true, so it breaks in unrelated ways when the coincidence changes, and no one can explain why. Deliberate code can be reasoned about and changed safely.

Signals

  • "I don't know why it works, but it does, so don't touch it."
  • Fixes found by trial and error rather than understanding.
  • Reliance on undocumented behavior, implicit ordering, or uninitialized values that happen to be right.

Benefits

Programming deliberately yields code you can explain, predict, and change with confidence, and assumptions made explicit instead of hidden.

Risks

The fragile kind looks productive in the moment, since the code passes today; the cost arrives later as inexplicable breakage. Mistaking "it passes" for "it is correct."

Tensions

Moving fast by accepting what works competes with the slower discipline of understanding why; the speed is borrowed against future debugging.

Examples

Depending on records coming back in insertion order from an API that never promised it; a timing fix that works only because an unrelated operation happens to be slow enough.