You might have seen programmers keeping rubber ducks on their desks. (See if you can spot the one in this tweet, for example!) But what on earth is the connection between a rubber duck and programming?
Well, itās all thanks to a concept called the rubber duck debugging method, or rubber duck programming.
Many coders keep a rubber duck toy on their desk as a reminder to talk through things and simplify problems. They explain the problem theyāre facing to the duck, or another inanimate object, out loud.Ā
When youāre breaking down problems and explaining code line-by-line to a friendly duck that wonāt judge you, it can help you see things from a new perspective. Rubber duck coding can help you find better solutions, think of easier algorithms to implement, etc.
In this post, learn more about what the rubber duck debugging technique is, where it came from, why and how it works, whether you can do rubber duck debugging without rubber ducks, and where to get your own coding rubber duck to join your desk decor!
Disclosure: Iām a proud affiliate for some of the resources mentioned in this article. If you buy a product through my links on this page, I may get a small commission for referring you. Thanks!
What Is Rubber Duck Debugging?
š¦ Rubber duck debugging (sometimes shortened as rubber-ducking) is a technique for debugging. The main idea behind it is that speaking out loud can help you solve problems.
What exactly is the function of a rubber duck for coding?
Coders use a rubber duck in programming (or other toy, stuffed animal, pet, inanimate object, etc.) because itās a small object that doesnāt bother anyone and can always sit on your desk as a reminder.
The duck serves as a way to help you externalize thoughts and work through a problem step-by-step, explaining each line of code and its purpose out loud in simple terms.
As Scott on Twitter says, āI can’t count the number of times I’ve called over a colleague to explain an issue I’m having to ask for help and then halfway through saying ā…oh, wait. Now I understand!ā without them saying a word.ā
By using your handy debugging rubber duck, you donāt have to interrupt any coworkers, and you donāt have to look crazy by just muttering to yourself. Instead, if anyone overhears, you can hold up your little friend and tell them āIām rubber duck debuggingāitās a thing!ā
Of course, if a coder still canāt figure out a solution after explaining it to the duck, they can then ask others for help. The rubber duck debugging technique is just a great starting point to get you thinking out loud.
āļø Back to top
Start coding now
Stop waiting and start learning! Get my 10 tips on teaching yourself how to code.
Where Did Rubber Duck Debugging Come From?
The origins of rubber duck debugging can be traced back to the book The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas, which was first published in 1999.
In that book, thereās a story that talks about how a programmer carries around a rubber duck and explains their code to it when they encounter a bug. The authors describe the technique as a way for developers to externalize their thoughts and better understand their code.
The term “rubber duck debugging” was coined in the early 2000s, and it has since become a widely recognized term in the software development community. It is often used humorously, but the rubber duck debugging method itself has proven to be an effective way for developers to catch errors and solve problems.
Ever since then, software engineers have used their own programming rubber ducks (and other objects) to help them think through code.
āļø Back to top
Rubber Duck Debugging Method
Rubber duck debugging is super easy. Here are the steps:
- š You have a bug, and the regular investigation process isnāt working for you to track it down in your code.
- š¦ Find your coding rubber duck and put them front and center on your desk, ready to get to work! (You could also recruit another inanimate object, a pet, or even a human friend.)
- š£ļø Explain the code line-by-line to your duck. Talk about why you coded something a certain way, what your goals are for the code, etc. The process of having to organize your thoughts and speak out loud can often make something āclickā in your brain. Try to explain your code or the bug as if youāre speaking to a child, or a duck that doesnāt understand code at all (which, after all, most ducks donāt!).
If there are times when the rubber duck debugging technique doesnāt work, then you can always ask other programmers for help. But since most developers prefer to spend some time doing their own troubleshooting first, having a helpful rubber duck for coding could be just the thing to lead you to a breakthrough.
āļø Back to top
Why Does Rubber Duck Debugging Work?
Even just having a rubber duck on your desk can help you solve problems! Here are some thoughts from coders on Reddit on why rubber duck coding works for them:
- strigonian: āIt helps protect you from making the mistake of skipping over “obvious” bits of code. People usually have a tendency to assume that certain parts are so simple or straightforward that they can’t possibly be wrong, so they shouldn’t waste their time scanning these bits. Explaining it to a āduckā helps to override this problem, because your āduckā doesn’t know anything, so nothing is obvious to the āduckā.ā
- hollammi: āSpeaking out loud is a fundamentally different process in your brain, e.g. it’s much easier to memorize information by repeating it aloud a couple times.ā
- PC__LOAD__LETTER: āA lot of the time I end up answering my own question by going through the process of explaining what Iāve tried and what Iām confused about.ā
- ElephantRyan: āI keep a small black rubber duck at my desk as just a reminder that the solution is usually in my head. I just need to slowly work through the problem. He’s my little motivation!ā
Science backs up the concepts behind using a rubber duck in programming, too! According to a study conducted by Gary Lupyan at the University of Wisconsin, self-talk helps boost your perceptual processing abilities.
Start coding now
Stop waiting and start learning! Get my 10 tips on teaching yourself how to code.
āļø Back to top
Does It Have to Be a Duck?
Despite its name, you can absolutely do rubber duck debugging without rubber ducks involved at all! You can use anythingāa toy, pet, stuffed animal, baby, etc! š±
Here are just a few examples from coders on Reddit and Twitter:
- Cats (āThey don’t care as long as I keep talking and cuddling them.ā)
- Stuffed animals
- A doll
- Pet dog
- ChatGPT
- Baby Yoda
- Partner/friend who doesnāt know code (āI don’t have a rubber duck, but I’ll start explaining the code to my wife, who has no idea what I’m talking about, and eventually figure it out. I call it using my sounding board to bounce ideas off.ā)
If a programmer rubber duck doesnāt feel like the right fit to you, think of what would make a good ācoding mascotā that fits your personality!
āļø Back to top
Where to Buy Ducks for Rubber Duck Debugging
Want to go with the ātraditionalā rubber duck for coding route? Hereās a quick list of some of our favorite programming rubber duck options:
- Classic rubber duck
- devDucks with capes that have specific programming languages on them
- Debugging paper duck
- An assortment of rubber ducks so you can pick one based on your mood that day, give them away to coworkers, etc!
While it may seem a little silly when you first hear of it, rubber duck debugging has become a widely recognized and accepted technique in the software development community, and it is likely to remain a valuable tool for developers for years to come.
Give it a try yourself to see why!