Problem Solving

Coding is 20% typing, 80% staring and asking “why”.

▶ the lesson · narrated sketch video · tap for sound

the intro

Problem solving is the actual job. The reliable loop: reproduce the bug, isolate the smallest failing case, form one hypothesis, change exactly one thing, test. Repeat until the mystery dies. Everything else is typing.

the sample

the oldest debugger in the world

console.log('here 1')
console.log('here 2')
// ...the classic
// it never prints 'here 2'

fun fact ✦

Most “impossible” bugs are a typo you have stared at for two hours. Take the walk. Really.

the docs

the deep dive

the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid

Debugging is not a talent some people are born with — it is the scientific method with worse lighting. You observe (reproduce the bug), guess (one hypothesis), experiment (change exactly one thing), and conclude. The engineers who seem psychic at bugs are not reading minds; they have just run more experiments and kept better notes.

the scientific method with worse lighting

reproduceisolateone changetest again
the loop: every pass that clears a suspect halves the mystery

key terms

repro case

A recipe that makes the bug fail every single time. Without one you cannot test a fix, only hope.

save with an empty cart field

hypothesis

One guessed cause, worded specifically enough to be proven wrong.

the id arrives as a string

bisect

Cut the suspects in half each round: the bug survives in one half, so the other half is cleared.

8 suspects becomes 4, then 2

heisenbug

A bug that vanishes or changes the moment you try to observe it, like adding a console.log.

disappears with logs added

how it works

  1. 1
    Nail the reproduction

    Find steps that fail 100 percent of the time before touching any code. A bug you cannot summon, you cannot verify fixed.

  2. 2
    Shrink the failing case

    Delete everything the bug does not need: one function, one input, one click. Smaller case, fewer suspects.

  3. 3
    State one hypothesis

    Write the full sentence: I think X fails because Y. Vague guesses produce vague experiments.

  4. 4
    Change exactly one thing

    Test. Same bug means revert and cross that suspect off the list. Fixed means you learned something real.

  5. 5
    Record the cause

    One line on why it broke, not just the edit. Patterns repeat, and past you left notes.

the code, explained

the oldest debugger alive: it never prints rate, so the line above is guilty

1function applyDiscount(cart) {
2 console.log('cart:', cart)
checkpoint 1: did the input arrive?
3 const rate = cart.promo / 100
suspect: promo is undefined here
4 console.log('rate:', rate)
never prints? the bug is the line above
5 return cart.total * (1 - rate)
6}

side by side

change one thing

  • each run clears or convicts one cause
  • reverting is always safe
  • you learn the system as you go
VS

shotgun debugging

  • five changes, none provably the fix
  • cannot explain what worked
  • new bugs land unnoticed
🪤 gotcha

The scariest outcome is a fix you cannot explain. It passes today, the real bug is still in there, and it will pick the busiest week of the quarter to come back. If you cannot say why the fix works, keep digging.

quick answers

How long should I struggle before asking for help?

Timebox it: 30 to 60 minutes of going in circles is the signal. Bring your repro case and the hypotheses you already cleared — that list saves your helper an hour.

Debugger or console.log?

Both. Logs for quick checkpoints along a path, breakpoints for freezing state mid-flight and inspecting everything at once. Breakpoints beat forty print statements.

What if the bug is inside a library?

Same loop, one level up: pin the version, read its issue tracker, build the smallest project that shows it. Half the time the answer is an upgrade.

quick hits about Problem Solving

short answers · interviews, tips, trivia & hidden gems

📚 tutorial

Binary-search your own codewatch ↗

🔧 useful

Flaky repro means flaky fixwatch ↗

🔧 useful

Steps to reproduce IS the debuggingwatch ↗

💎 deep

Take the walkwatch ↗