The Wrong Way to Debug
The most common debugging approach I see is: change something, see if it helps, change something else, see if that helps. This is random walk debugging. It works eventually, but it's the slowest possible method and leaves you with no understanding of why the bug existed.
The faster approach is scientific: form a hypothesis, test it specifically, update your model.
Start With a Model, Not a Fix
Before touching any code, answer these questions:
- What did you expect to happen?
- What actually happened?
- What is the smallest possible difference between those two things?
The gap between expectation and reality is where the bug lives. Your job is to narrow that gap systematically.
The Bisection Technique
If you don't know where the bug is, bisect. Add a checkpoint halfway through the execution path. Is the state correct there? If yes, the bug is in the second half. If no, the first half.
This is git bisect applied to code. It turns an O(n) problem into O(log n). You'd be surprised how many engineers still do linear search through their codebase when they could bisect.
Verbalising Out Loud
This is the mechanism behind rubber duck debugging. When you explain your code out loud, you're forced to be explicit about your assumptions. Your brain fills in gaps when reading code silently. It can't do that when speaking.
The practical version: before asking a colleague for help, write one paragraph explaining the bug. You'll solve it before you send it at least half the time.
When You Find It
When you find the bug, don't just fix it. Ask:
- Why did this happen?
- What assumption was wrong?
- Could this class of bug exist elsewhere in the codebase?
- What would have caught this earlier (a test, a type, a linter rule)?
A bug fixed without understanding is a bug that comes back.
The Skill That Transfers
The debugging mindset — hypothesis, test, update — is just the scientific method applied to software. It transfers to everything: performance investigations, system design, product decisions.
The engineers I've seen grow fastest are the ones who bring genuine curiosity to failures rather than frustration.