Rubber duck debugging, Rubberducking, or any of the other names it goes by. What is it? Why does it work? and how does it improve your debugging?
What is Rubber Duck Debugging?
We’ve nearly all experienced the phenomenon. You are stuck debugging a problem and ask someone to pair with you to help work it out. As you explain the code and problem to the person pairing with you, you realise what the problem is without them saying a word. This phenomenon is what Rubber Duck Debugging refers to.
The name references a story in The Pragmatic Programmer, in which a programmer carries a rubber duck. They debug their code by by explaining the code, line-by-line, to their rubber duck, in an effort to induce the above phenomenon.
Why does Rubber Duck Debugging work?
In application to programming, explaining our process breaks our ego — thinking we’re doing it right. When facing a bug, we often say, “But I’ve done everything I needed to do!”. Trying to explain it to ourselves raises the question of this prideful claim with a “Did I do everything I needed to do?”.Arnold C Subastil
By forcing ourselves to explain the intention of our code, and the approach we have taken to achieve that outcome, it forces us to stop assuming that what we have done is right. By stepping through the code and explaining the purpose of each section can help us to spot our own mistakes or false assumptions.
There is also a separate psychological explanation that by explaining something, it causes us to deeper analyse our answer in order to be confident that our answer satisfactorily answers the problem or question. In doing this deeper analysis we improve our own understanding.
How does Rubberducking improve your coding?
So how can you use Rubber Duck Debugging to improve your coding? Simple. Start doing it! By taking the time to explain the problems with your code to someone else, whether that someone else is a colleague, a pet or a rubber duck, you will improve your understanding of your code and the problems you are facing and so you are less likely to encounter those problems in the future. In the worst case, you are likely to have a better idea of what your issue is and so have more success in finding a solution.
The Psychology Behind Rubber Duck Debugging – Arnold C Subastil
Why does explaining to others help us understand? – Natalie Wolchover
Explaining to yourself can be a powerful mechanism for learning – Tania Lombrozo
How we reduced deployment lead time by 480 hours – Stuart Thomas
Subscribe to The Quality Duck
Did you know you can now subscribe to The Quality Duck? Never miss a post but getting them delivered direct to your mailbox whenever I create a new post. Don’t worry, you won’t get flooded with emails, I post at most once a week.