Ask a room full of developers whether they have a rubber duck on their desk and you will see a surprising number of hands. It is not just a joke. It is a debugging method, and it has a name: rubber duck debugging.
What is rubber duck debugging?
When your code does not work and you cannot see why, you explain it, out loud and line by line, to a rubber duck. What each line should do, what it actually does, what you expect the value to be. Somewhere halfway through, you hear yourself say something that is not true. That is the bug.
Where it comes from
The term became popular through The Pragmatic Programmer by Andrew Hunt and David Thomas (1999), which tells the story of a programmer who carried a rubber duck around and debugged his code by explaining it to the duck. The idea itself is older: you only really understand something once you can explain it.
Why it works
- It slows you down. Reading code in your head, you skim. Explaining it, you cannot skip a line.
- It forces you to state your assumptions. Bugs usually live in the thing you were sure about.
- The duck does not interrupt. A colleague would jump in with a guess. The duck lets you finish the thought.
- It saves your colleagues' time. Half the questions you were going to ask get answered before you ask them.
How to do it
- Put the duck where you can see it. Yes, really.
- Tell it what the code is supposed to do, in one sentence.
- Go through the code line by line and say what each line does.
- When what you say and what the code does stop matching, you found it.
- Thank the duck. Optional, but recommended.
It works for more than code: spreadsheets, a difficult email, a plan that does not quite add up.
Pick your debugging duck
Any duck works, but a duck with some character is easier to talk to.
Danny Developer is our developer's favourite, Einstein is for when the problem feels bigger than it is, Peter Project for the project manager who wants to understand the bug too, and Sleepy for the 2am deploy.
3 ducks −10%, 5 or more −15%. Mix any you like; the discount is applied automatically in your cart. Spend €35 or more and a Sharky keychain is added to your order for free. Shipped within 1–2 days, 14 days to return.
A duck is also a great welcome gift for a new developer on the team. The Professions collection has one for the rest of the office too.
Frequently asked questions
Does rubber duck debugging really work?
Yes. Explaining a problem step by step forces you to check every assumption, which is exactly where most bugs hide. Many developers find the bug before they finish explaining.
Do I have to talk out loud?
It works best out loud, but whispering or typing the explanation also helps.
Where does the name come from?
From the book The Pragmatic Programmer (1999), in which a programmer debugs his code by explaining it to a rubber duck.
What is a good gift for a developer?
A rubber duck for their desk is a classic. It is useful, it is a conversation starter and every developer gets the joke.
Danny Developer
Einstein
Peter Project
Sleepy