The Bug That Changed How I Write Code Forever

·1 min read·

One off-by-one error in a financial reconciliation loop. Three days. The session that permanently changed my approach to defensive programming.

A financial reconciliation loop. One off-by-one error causing settlement to drift by a fraction of a penny per transaction.

At 2 million transactions a year, that fraction adds up.

Three days to find it. Thirty seconds to fix it.

What I learned permanently: write code that makes wrong states unrepresentable. Use database constraints to enforce correctness. Write assertions that fail loudly. Log every financial state transition with before-and-after snapshots.

The best debugging is the debugging you never do because the code cannot produce the wrong answer. Design for that.

— Dick Bassey | DevDick | 2018

Share this article
← Back to all writing