The rubber duck method, also called rubber duck debugging, means explaining your code, line by line, to something that can't answer back, usually a small rubber duck on your desk.
It sounds silly, but saying what each line does out loud is one of the quickest ways to find a bug you have been staring past for an hour.
Where the idea comes from
The name comes from The Pragmatic Programmer by Andrew Hunt and David Thomas, published in 1999. The book tells the story of a programmer who carried a rubber duck around and debugged code by forcing themselves to explain it, line by line, to the duck.
The duck is a stand-in. What matters is the explaining. You could talk to a houseplant, a mug, or a colleague who never says a word, and get the same benefit. The duck just makes the habit easy to remember, and a bit less awkward than talking to an empty room.
Why explaining finds bugs
When you read your own code, you read what you meant to write, not what is there. Your brain already knows the plan ('fetch the order, apply the discount, save it'), so it skims each line, sees roughly the right shape and moves on. The bug lives in the gap between the plan in your head and the code on the screen.
Explaining closes that gap. To say a line out loud you have to:
- Slow down. You can't skim a sentence you are speaking. Each line gets its own moment.
- Put each step into words. 'Then this runs' is not enough once you have to say what 'this' is and what it returns.
- State your assumptions. 'This list is never empty' or 'this function only runs once' sounds fine in your head and suspicious said out loud.
- Explain from the start. A listener knows nothing, so you begin at the top instead of jumping straight to the line you are sure is broken.
Somewhere in that process, the sentence you are saying and the code in front of you stop matching. That moment, the 'wait, why does it do that?', is the bug.
The duck never fixes anything: you find the bug yourself, and the duck gives you a reason to explain.
Wondering how this was made? How we make these