What
Rubber duck debugging is the practice of explaining a problem to a non-expert (or inanimate object) step by step. The act of articulation forces you to make implicit assumptions explicit. Protocol: (1) Describe what the code/system SHOULD do. (2) Describe what it ACTUALLY does. (3) Describe each step in between, out loud. (4) The bug appears at the step where description and reality diverge.
It works because you know more than you have made explicit — speaking forces serialization of tacit knowledge. Extend the technique by writing the explanation as a comment before the code. If you cannot explain it, you do not understand it. Also applies to planning: "explain the plan" before implementing often reveals the flaw.
When to Use
Use rubber duck debugging when stuck on a bug, when you cannot figure out why something is not working, or when planning a complex implementation. If you have been staring at the same code hoping the answer appears, use this technique immediately.
How
- Find a patient listener (person, stuffed animal, or empty terminal).
- Describe what the code SHOULD do, step by step.
- Describe what it ACTUALLY does, step by step.
- Identify where description and reality diverge — that is your bug.
- Beware the anti-pattern: staring at the same code hoping the answer appears.