Concept

Programming by Coincidence

Definition

Programming by coincidence is the habit of writing code that seems to work, accepting that result, and moving on without knowing why it works. The program runs, the test passes, and the developer treats apparent success as proof of correctness.

The danger is that the code may be working by luck: relying on an undocumented behavior, an accidental ordering, or a state that happens to be set elsewhere. When the coincidence ends, the code fails, often far from where the real problem lives.

Why it matters

How it works

Programming by coincidence usually starts with copy-pasted snippets, undocumented APIs relied on by observation, or assumptions about timing and order that were never guaranteed. Each one is a hidden assumption, and assumptions accumulate silently.

The antidote is deliberate programming. Rely only on documented, reliable behavior. Do not assume something is true, prove it. When you cannot explain why a piece of code works, treat that as a defect to investigate, not a success to ship. Knowing why is what makes change safe.

Where it goes next

Continue exploring

Tags