๐Ÿ›
๐Ÿ› Debugging & Problem-Solving ยท DEBUG-101 ยท Session 4 of 6

Isolate the Problem

The fastest way to find a bug is to shrink the search area until the bug has nowhere to hide. Bisecting, minimal examples and the rubber duck are the professional's core techniques.

โฑ 9 min read๐Ÿ“… Updated 2026-07-30๐Ÿ“Š Tables, charts & examples

When a bug is hiding somewhere in a hundred lines, staring at all hundred is hopeless. The professional move is to shrink the search area until the bug is cornered. A few simple, powerful techniques do this: bisecting (halving the problem), building a minimal example, and the famous 'rubber duck'. Master these and you'll find bugs faster than people who just read code harder.

Bisect: halve the problem

Instead of searching everywhere, cut the problem in half, find which half has the bug, and repeat. A few halvings corner even a well-hidden bug.

StepWhat you do
Check the middleIs the data still correct halfway through?
If wrong thereThe bug is in the FIRST half - search there
If right thereThe bug is in the SECOND half - search there
RepeatHalve again until you've cornered it

This is the same idea as binary search from DS-101, applied to finding bugs. Each check roughly halves what's left to search, so even a bug buried in a long program is found in a handful of steps. Comment out half the code, or print at the midpoint - either way, keep halving.

Minimal example and the rubber duck

Two more techniques that feel almost too simple to work - but work remarkably well.

๐ŸŽฏ
Explain the problem out loud, line by line - the 'rubber duck'. Programmers keep a rubber duck on their desk to explain their code to, because the act of explaining a problem step by step, out loud, to something that can't help you, astonishingly often reveals the bug mid-sentence. You say 'and then this returns the list, and then I loop over it and... oh. It's empty.' Forcing yourself to articulate what each line does breaks the assumption that was hiding the bug. The other technique - a minimal example - means stripping the problem down to the smallest bit of code that still shows the bug, away from everything else. Often, building that tiny example reveals the cause before you even finish.

Corner the bug

  • Bisect - halve the search area, find the bad half, repeat (binary search for bugs).
  • Minimal example - shrink to the smallest code that still shows the bug.
  • Rubber duck - explain it out loud, line by line; the bug often reveals itself.
  • Shrink, don't stare - reducing the search area beats reading harder.

๐Ÿงฉ Do it with LarzOS

Turn this lesson into action with the exact free tools and AI workflows for the job:

๐ŸŽฏ Key takeaways

  • The fastest way to find a bug is to shrink the search area until it has nowhere to hide.
  • Bisect: check the midpoint, find which half holds the bug, repeat - binary search for bugs.
  • A minimal example strips the problem to the smallest code that still shows the bug - often revealing the cause.
  • The rubber duck: explaining the code out loud, line by line, astonishingly often reveals the bug mid-sentence.

Frequently asked

Why would explaining my code to a rubber duck actually help? It sounds silly.

It sounds silly and it genuinely works - the technique is named 'rubber duck debugging' and it's widely used by professionals for a real cognitive reason. When you read your code silently, your brain skims, filling in what you expect to be there rather than what actually is - which is precisely how bugs stay hidden, since the bug is usually a gap between your assumption and reality. Explaining the code out loud, step by step, to another person (or a rubber duck, or an empty chair) forces you to slow down and articulate what each line really does, in order, without skipping. That act of putting it into words breaks the skim: you can't hand-wave 'and then it gets the list' when saying it aloud forces you to actually check that it does get the list - and that's the moment you notice it's empty, or the wrong type, or never assigned. The duck doesn't need to understand or respond; the value is entirely in you being forced to explain clearly. It's a way of catching your own hidden assumptions by making them explicit. Try it the next time you're stuck - talk through the problem line by line as if teaching it - and you'll be surprised how often the answer surfaces before you finish. It costs nothing and it's a real, respected technique, not a joke.

Isolating sounds like a lot of extra work - isn't it faster to just find the bug directly?

It feels like extra work, but isolation is almost always faster overall, especially for bugs that aren't immediately obvious - which are exactly the ones that eat your time. Trying to 'just find it directly' in a large, tangled program means holding many possibilities in your head at once and often making random changes hoping something helps, which tends to introduce new bugs and waste hours. Isolation replaces that with a systematic narrowing: each halving or simplification cuts the possibilities dramatically, so a few quick steps corner a bug that could otherwise hide for ages. Building a minimal example, in particular, does double duty - it either reveals the cause as you strip things away (very common), or it gives you a tiny, clear case to reason about instead of a huge messy one. There's a real sense in which the fastest path through a hard bug is the disciplined one, not the impatient one. For a trivial bug that the error message points straight at, sure, fix it directly - isolation is for when the cause isn't obvious. But the moment you find yourself staring, confused, changing things at random, that's the signal to stop and isolate: halve the problem, shrink it down, explain it out loud. It converts a frustrating open-ended hunt into a short series of concrete steps, and with practice it becomes your reliable default for anything that doesn't yield immediately.

Session 4 of 6 complete

Next up: Common Bugs and How to Spot Them

Continue to Session 5 โ†’

Related lessons

More in this course

Course home → · Browse all courses →