techlifeadventuresVol. 03 · Nov 2026
Rubber Duck Debugging: Why Developers Talk to Themselves
·7 min read·Culture & Lifestyle

Rubber Duck Debugging: Why Developers Talk to Themselves

Where rubber duck debugging comes from, the research on why explaining aloud works, a step-by-step method, and how to use it when the duck is an AI chat.

If you've ever walked past a developer's desk and caught them explaining code to a bath toy, you've seen rubber duck debugging in action. It looks silly. It is also one of the most reliable debugging tools I've used in twenty years of writing software, and the reason it works is more interesting than it sounds.

Where the name comes from

The term comes from a story in The Pragmatic Programmer (1999) by Andrew Hunt and David Thomas. A programmer kept a rubber duck on his desk and explained his code to it, line by line, before calling over a human. He usually found the bug before he needed the human.

The idea caught on. Some teams keep yellow ducks. Others use action figures, plush toys or potted plants. The object doesn't matter. The act of explaining out loud does.

Why explaining works

Working memory is small

Deep in a debugging session you're holding variables, branches and call paths in your head at once. Working memory is limited, and when it's full you stop seeing problems clearly.

Explaining the code aloud forces you to turn that jumble into a sequence of plain statements. You can only say one thing at a time, so you have to put things in order. Gaps and contradictions show up when you try to say them.

The self-explanation effect

There is solid research behind this. In the late 1980s, cognitive scientist Michelene Chi and colleagues studied students learning physics from worked examples. The students who explained each step to themselves understood the material better and solved new problems more successfully than those who just read the steps. Later work by Chi's group found that prompting people to self-explain improved their understanding. This is usually called the self-explanation effect, and rubber duck debugging is a practical use of it.

Two translations catch more errors than one

When you write code, you translate an idea into syntax. When you explain code, you translate the syntax back into an idea. Each translation is a chance to notice that what you meant and what you wrote are different. That gap is where most bugs live.

The listener doesn't need to understand

A duck offers no feedback. It doesn't interrupt, doesn't get bored, and doesn't jump in with a fix before you've finished thinking. A helpful colleague might hand you the answer too early, and you lose the chance to see the problem yourself. With a duck, you have to do all the work, and that is the point.

A step-by-step method

1. Pick your duck

Any object works: a rubber duck, a toy, a plant, a sticky note with a face on it. Put it somewhere you can see it.

2. State the problem in one sentence

"The discount total is wrong when the cart has more than one item." Being specific about what's broken shapes the rest of the explanation.

3. Explain line by line, out loud

Start at the top of the problem area and say what each line does. Be concrete:

  • Not: "This function doesn't work."
  • Instead: "This function takes a price and a discount of 0.2. It multiplies the price by the discount... and returns that. Wait, that's the discount amount, not the discounted price."

4. Trace it with real inputs

Walk through the code as if you were the computer:

"Price is 100, discount is 0.2. We multiply, get 20, and return 20. The customer should pay 80. We're returning the discount instead of the price after discount."

5. Confirm with a test

The duck helps you find the bug. A test proves it, and keeps it from coming back.

6. Write down what you learned

A one-line note in a debugging log or the commit message makes the lesson stick.

Three typical cases

These are illustrative composites of common bug types, not stories about specific people.

The loop that never ends. A developer stares at a while loop that should stop after ten passes. Saying it aloud goes: "We start i at 0. While i < 10, we process the item, and if the item is valid we increment i..." The increment is inside the if. One invalid item and the loop never moves on. Reading the code missed it. Saying "if the item is valid" out loud did not.

Variable shadowing. "We set user in the outer function. Then inside the callback we declare var user again..." In JavaScript, var is function-scoped, so the inner declaration shadows the outer one for the whole callback. The data was right going in and wrong by the time it was used, because it was a different variable.

The missing await. "We await fetchData() and get the response. Then we call processData(response). Then we return." Said slowly, it's obvious: processData is async and nobody awaits it, so the function returns before the processing finishes.

When you can't use a physical duck

  • Write the question. Drafting a detailed question for a forum or a colleague often answers itself before you send it.
  • Write the PR description or issue first. Walking through what a change does, in order, catches mistakes for both you and the reviewer.
  • Ask a colleague to just listen. Tell them up front not to suggest anything until you're done.
  • Keep a scratch file. Typing the explanation works almost as well as saying it.

The duck that talks back: AI chat

Today a lot of developers explain their bug to an AI assistant instead of a duck. That can work well, but it changes the exercise. An AI answers. If you paste the code and ask "what's wrong?", you skip the explaining, which is the part that does the work.

A better approach is to write the explanation first, in my own words, as if the AI were the duck: what the code should do, what it actually does, and what I've already ruled out. Often you spot the problem while writing that message. When you don't, the AI gets a much clearer prompt than a raw code dump, and its answer is better for it.

Practical tips

  • Explain intent before behaviour. Say what the code is supposed to do, then what it actually does. The difference is the bug.
  • Explain the "why". "We add five because the API needs a minimum offset of five" exposes assumptions that "we add five" hides.
  • Slow down. Ten minutes on twenty lines is fine. Skimming is how you missed the bug the first time.
  • Use it first, not instead. It doesn't replace a debugger, logging or code review. It's the cheapest thing to try before you reach for them.

The bottom line

Rubber duck debugging works because explaining forces you to put your thinking in order, and the research on self-explanation backs that up. It costs nothing, needs no tools, and works on the bugs that survive staring at the screen.

Next time someone asks why you're talking to a rubber duck, tell them you're debugging.


Related Reading:

Enjoying this article?

Get posts like this in your inbox. No spam, unsubscribe anytime.

Share this article
Vinod Kurien Alex

Vinod Kurien Alex

Engineering Manager with 20+ years in software. Writing about AI, careers, and the Indian tech industry.

Related Articles

© 2026 TechLife AdventuresBuilt with care · v3.2.1