Systematic Debugging

4.Think Like a Good Mechanic

A

In this chapter

We'll learn debugging as a method instead of luck — reproduce, isolate, form a hypothesis, test it, fix — explained as how a mechanic finds a strange noise in a car, and use it to finally catch the hour bug.

14–16 min

The Problem in Real Life

Liam has a suggestion: "Just subtract one hour in the code. Done." John shakes his head. "And in March, when the clocks change and the servers move, it'll be wrong in a new way. If you don't know why it's wrong, your fix is just another bug."

He draws a loop on the whiteboard: Reproduce → Isolate → Hypothesis → Test → Fix. "Every good debugger in the world does some version of this. Let's do it slowly, once, so you never have to guess again."

J

Guessing feels fast. It's the slowest way there is.

John

Guessing and Patching vs. a Method That Always Works

Patching symptoms

"Just subtract one hour" hides the bug for a while — and creates a new one later.

Bugs you can't repeat

If you can't make the bug happen on purpose, you can't prove you fixed it.

Too many places to look

A web app has thousands of lines. You need a way to shrink the search fast.

Reproduce, Isolate, Hypothesise, Test

The mechanic analogy: your car makes a strange noise. A bad mechanic replaces random parts until it stops. A good mechanic first makes the noise happen while they listen (reproduce). Then they narrow it down: only when turning? only at speed? front or back? (isolate). Then they make a specific guess: "a worn joint on the front-left wheel" (hypothesis). Then they check that one thing (test). Only then do they replace a part — the right one (fix).

  • 1. Reproduce — make it happen on purpose: find exact steps that make the bug appear every time. A bug you can reproduce is half solved; a bug you can't reproduce can't be proven fixed. If it only happens somewhere else (production, one customer's phone), list what's different there — data, settings, versions, timezone, browser — and try to copy those differences on your machine.
  • 2. Isolate — shrink the search area: remove everything that isn't the problem. Which page? Which function? Which input? A powerful trick is halving: check the value in the middle of the journey. If it's already wrong there, the bug is in the first half; if not, the second half. Repeat. Ten halvings narrow a thousand lines down to about one. (Git can do the same over commits with git bisect.)
  • 3. Hypothesis — one specific, testable guess: not "something's off with time", but "formatShowTime uses the machine's timezone, and production machines are set to Europe/Berlin". A good hypothesis predicts something you can check: "if I set my laptop's timezone to Berlin, I'll see 9:00 PM."
  • 4. Test the hypothesis — try to prove it wrong: run the check. If the prediction comes true, you've probably found the cause. If not, the hypothesis is wrong — which is useful too: cross it off and form the next one. Change one thing at a time, or you won't know which change mattered.
  • 5. Fix the cause, not the symptom: fix the real cause, then confirm that the original steps no longer reproduce the bug — and write a test so it can never return (chapter six).
  • Rubber duck debugging: explaining the problem, out loud and step by step, to someone — or even a rubber duck on your desk — is surprisingly effective. Halfway through explaining, you often hear your own mistake.
Table — Isolating the hour bug, step by step
CheckValueCorrect?
Database: stored show time2026-11-14T20:00:00ZYes
API response: raw show time2026-11-14T20:00:00ZYes
formatShowTime() result, laptop in London8:00 PMYes
formatShowTime() result, laptop set to Berlin9:00 PMNo — bug reproduced
Table — Guessing vs. a method
GuessingSystematic debugging
Change several things at onceChange one thing at a time
"Subtract one hour"Find why it's one hour
Can't say why it works nowCan explain the cause in one sentence
Bug returns in MarchFix holds wherever the code runs

The debugging loop

Reproduce

TZ=Europe/Berlin → 9:00 PM on her laptop

shrink the search

Isolate

data OK · API OK · formatShowTime wrong

one specific guess

Hypothesis

getHours() uses the machine's timezone

try to prove it wrong

Test

New York timezone → 3:00 PM, as predicted

confirmed

Fix the cause

format in the venue's timezone

Reproducing and testing the hypothesis
TZ=Europe/Berlin npm run dev # page shows 9:00 PM -> reproduced
TZ=America/New_York npm run dev # page shows 3:00 PM -> hypothesis confirmed
TZ=Europe/London npm run dev # page shows 8:00 PM -> why laptops looked fine
The fix: format in the venue's timezone
function formatShowTime(showTime, venueTimeZone) {
return new Intl.DateTimeFormat("en-US", {
timeZone: venueTimeZone, // e.g. "Europe/London" — where the show happens
hour: "numeric",
minute: "2-digit",
hour12: true,
}).format(showTime);
}
formatShowTime(new Date("2026-11-14T20:00:00Z"), "Europe/London"); // "8:00 PM"

The result no longer depends on the server's timezone — only on where the show happens.

Reproduce: the difference between laptops and production is the timezone. In the terminal, Anna starts the app with a different timezone: TZ=Europe/Berlin npm run dev. She opens the Riverside Arena page. 9:00 PM. Reproduced on her own laptop. She grins; John doesn't — "Not done yet."

Isolate: is the data wrong, or the display? She checks the database: the show is stored as 2026-11-14T20:00:00Z — correct. She checks the API response (next chapter): the raw time is correct too. Only the formatted text is wrong. So the bug is inside formatShowTime — the one function she watched in the debugger.

Hypothesis, tested: "getHours() uses the machine's timezone." Prediction: with TZ=America/New_York, the page will show 3:00 PM. She tries it. 3:00 PM. Confirmed — the show's time depends on where the server is, which makes no sense for a concert that happens in London.

The real fix: a show's time belongs to its venue, not the server. Every venue in the database already has a timezone (Europe/London for the Riverside Arena). Anna changes formatShowTime to format the time in the venue's timezone, using the built-in Intl.DateTimeFormat. Now it doesn't matter where the code runs: London, Berlin, New York — the Riverside Arena's show is always at 8:00 PM. And it handles the clock changes in March and October automatically.

Key Takeaway

Debug like a good mechanic, not by replacing random parts. Reproduce the bug on purpose (copy whatever is different where it happens). Isolate it by halving the search area. Form one specific hypothesis that predicts something, then test it, changing one thing at a time. Fix the cause, not the symptom — the hour bug was fixed by using the venue's timezone, not by subtracting an hour.

Why This Matters

The difference between a junior and a senior debugger is rarely intelligence — it's method. Reproducing first, isolating by halving and testing one hypothesis at a time works on every kind of bug, in every language, for your whole career. And fixing causes instead of symptoms stops the same bug from coming back in a new disguise.

The fix works on her laptop with every timezone she tries. Before she opens a pull request, John wants her to check the whole page in the browser — and to see what the browser itself can tell her.