Programmers keep rubber ducks on their desks to debug by explaining. When code does not work, you explain it to the duck, line by line, out loud. Somewhere in the explanation you say what the code should do, notice what it actually does, and find the bug. The duck never answers. It does not need to. The method is called rubber duck debugging, or just rubberducking.
Where rubber duck debugging comes from
The name comes from The Pragmatic Programmer by Andrew Hunt and David Thomas, published by Addison-Wesley in October 1999. In the section on debugging, the authors tell the story of a programmer who carried a rubber duck and explained problems to it. They describe the effect: you start to explain what the code is supposed to do, and the problem appears on its own. Wikipedia traces the name to that anecdote, and its article on the book credits it with popularising the term.
The idea is older than the duck. Brian Kernighan and Rob Pike, in The Practice of Programming (also 1999), advise explaining your code to someone else, and tell of a university computer centre that kept a teddy bear next to its help desk. Students with mysterious bugs had to explain them to the bear before they could talk to a human. A review of the book at Imperial College points to that advice on page 123. Same method, different toy.
How to do it
- Put the duck where you can see it. Any object works: a plant, a mug, a patient colleague.
- State the goal in one sentence: “This function should return the average of a list.”
- Read the code aloud, one line at a time. Say what each line does, not what you hoped it does.
- Explain every value. Where does it come from? What is it now? What should it be?
- When you hear yourself say “and then obviously…”, slow down. The bug usually lives there.
A rubber duck debugging example
This Python function should return the average of a list. For [2, 4, 6] it returns 3.33 instead of 4.0:
def average(values):
total = 0
for i in range(1, len(values)):
total += values[i]
return total / len(values)
print(average([2, 4, 6])) # 3.3333333333333335
Now explain it to the duck. “I start with a total of zero. Then I loop over every value, starting with the first one, which is… index 1.” That is where you stop. range(1, len(values)) starts at the second element, so the loop never adds values[0]. The total is 4 + 6 = 10, divided by 3.
Reading the code silently, your brain sees what you meant to write. Saying it aloud forces you to read what you actually wrote. The fix is one line:
def average(values):
return sum(values) / len(values)
print(average([2, 4, 6])) # 4.0
An empty list still raises ZeroDivisionError. Explain that edge case to the duck too.
Why it works
Explaining needs a complete story. When you only read code, you can skip the parts you think you know. When you explain it, you cannot skip a step without noticing the gap. That gap is often the bug.
The duck also helps because it is not a person. You do not interrupt a colleague, you do not feel silly about a simple mistake, and you can start again as many times as you need. Many developers know the version without the duck: you write a long question to a coworker, find the answer while typing it, and delete the message.
The same thinking helps with the opposite problem, when code works and you do not know why. We cover that in It works, why?.
Why programmers have rubber ducks on their desks
Partly because the method works. Partly because it became a symbol. A rubber duck on a monitor tells everyone the owner writes code, and it costs almost nothing. Some teams hand out ducks to new hires. Some help desks ask people to “talk to the duck” before they open a ticket, which is the teddy bear story again.
It is also one of the few programming jokes that non-developers already understand. That makes it an easy gift: a duck for the desk and a shirt that explains it.
The duck as a shirt
Our Quack the Code shirt makes the duck the senior engineer of the team. It sits with our other debugging jokes in the developer t-shirts.

Quack the Code Rubber Duck T-Shirt · 24 €
The senior engineer who never says a word.

Debugging Definition T-Shirt · 24 €
The detective who is also the murderer.

It Works, Why? Developer T-Shirt · 24 €
For when the duck fixed it and you are not sure how.
Unisex fit, S to 5XL, printed on demand. Check the size guide. Buying for a student? See our gifts for programmers under $30, or the Christmas gift guide for programmers.
FAQ
What is rubber duck debugging?
A debugging method: you explain your code, line by line, to a rubber duck or any object. Explaining makes you notice the step that does not match your intent.
Who invented rubber duck debugging?
The name comes from a story in The Pragmatic Programmer (Hunt and Thomas, 1999). The idea of explaining bugs to a listener is older; Kernighan and Pike tell a similar story with a teddy bear.
Does it have to be a duck?
No. A plant, a cat or a colleague works. The duck is just the most famous listener.