What is Rubberducking? An Explanation of the Rubber Duck Debugging Technique
Rubberducking is a problem-solving technique where you explain your code or task to a rubber duck—or any inanimate object—and discover the solution yourself through the act of explaining. It's brilliant because it works and is effectively free.
Rubberducking, or rubber ducking, is most commonly associated with debugging in software development but can be applied to any problem-solving process.
The name comes from the book The Pragmatic Programmer by Andrew Hunt and David Thomas. In it, the authors suggest using a rubber duck as a conversation partner to clarify one’s thoughts. This is an accessible and effective way to troubleshoot problems without requiring someone else’s time.
How Rubberducking Works
Have you ever been called over to someone’s desk to help them solve a problem, and as they explain the problem to you or demonstrate it, they figure out the answer themselves? It happens all the time to me, particularly when someone's showing me how something doesn't work, and it magically works just by having me watch over their shoulder.
The rubber duck technique is as simple as that, except that instead of calling someone over, you can simply replace the person with a rubber duck, teddy bear or heck, even your stapler.
The psychology behind rubberducking relies on how explaining a problem forces you to process your thoughts more clearly, often revealing gaps or errors in your understanding. Here’s how you can try it yourself:
1. Set up your “duck”: Place a rubber duck, teddy bear, or any object on your desk.
2. Explain your problem: Describe your code, logic, or issue to the duck, step by step, as if you’re teaching it.
3. Watch for insights: In explaining it aloud, you’ll often uncover what’s wrong or identify a new approach to solving it.
For example, a developer struggling with a bug might explain every line of code to the duck. Verbalising their logic can highlight an overlooked detail that resolves the problem.
Why Rubberducking is Effective
Rubberducking works because it forces you to articulate your thoughts clearly, moving them from abstract notions in your head to concrete statements. This shift can:
• Help you identify assumptions you didn’t realise you were making.
• Reveal errors or gaps in your logic.
• Mimic the process of pair programming without needing another person.
Rubberducking a problem also reduces dependency on others for problem-solving, making it a cost-effective—basically free!—and time-efficient tool for debugging.
Common Scenarios for Rubberducking
Here are some situations where it’s particularly useful:
• Debugging code: Talk through an error or bug in your program.
• Explaining logic: Test the clarity of your solution by explaining it step by step.
• Learning new concepts: Summarise a concept to the duck to check your understanding (see the Feynman Learning Technique)
• Decision-making: Walk through the pros and cons of a decision.
Rubberducking in Software Development
In software development, rubber duck debugging has become a recognised term for this process. It’s so common that some developers keep an actual rubber duck on their desks to symbolise this practice. Teams might 'joke' about needing “a duck” for the simplest bugs.
Debugging is an integral part of coding, and the rubber duck technique makes it less daunting. By verbalising your thought process, you streamline problem-solving without needing external help.
Frequently Asked Questions about Rubberducking
Q: Does it have to be a rubber duck?
Nope. While a rubber duck is the classic choice, you can use anything nearby—your coffee cup, a stapler, or even a photo on your desk.
Q: What if talking out loud isn’t possible?
Writing out your explanation or saying it in your head can work just as well. The key is clarifying and articulating your thought process.
Q: How is this different from pair programming?
Pair programming involves working alongside another person on the same task. Some people swear by pair programming, and to be honest, I've always found it effective whenever I try it. However, rubberducking is a solo activity where the act of explanation itself is the solution.
Next time you're stuck on something, grab a rubber duck and give it a try.
Related Ideas to Rubberducking
Also see:
- The Feynman Learning Technique
- The XY Problem
- Bugs and releases
- The cost of fixing bugs
- Yesterday's weather
- Yak shaving
Rubberducking is similar to the empty chair technique for psychotherapy, which involves speaking to an empty chair as if addressing a person.
It's also easily confused with "rubbernecking," which is slowing down to look at an accident as you drive past—a common cause of traffic jams.