Happy Rubber Duck Day! Even though it’s just celebrated in the USA, we can all take a few seconds to send some appreciative thoughts towards the rubber ducks around the world. You’ve most probably encountered a rubber duck throughout your time on Earth. But in case you’ve never seen one, scroll down a bit to see what’s it about. They’re a pretty popular prop used in TV shows/movies or in the tech world.
If you’re wondering what rubber ducks and the tech world have in common, keep on reading. Rubber Duck Debugging is a method used by developers to gain more clarity on their code’s logic and flow. Basically, your rubber duck is your silent partner in crime. It listens to what you have to say without interrupting you in any way (well, yea, it’s a rubber duck). This way, you can narrate each step of your code, in detail, to the duck, until you notice a problem or something that could be improved in your code. In the following lines, we talked about the origin of this method and answered some of the possible FAQs.
What’s the origin of this method?
In the book The Pragmatic Programmer by Andrew Hunt and David Thomas, there’s a story about a programmer who carries around a rubber duck who debugs their code by forcing themselves to explain each line of code to the duck. Programmers often tend to find solutions to their problems by discussing in detail the situation with someone. When developers mainly work alone and there aren’t colleagues available, having an object to which they can talk whenever they feel stuck makes the process more efficient.
David Hayes had an interesting take on the psychology of Rubber Duck Debugging on his blog Thoughtful Code:
“We use ducks and other stand-ins because of the vast difference between the way most humans think and the way that computers do. When you hit a roadblock when programming, it’s likely that you’re not thinking the way a computer does. Computers are painfully precise. Humans are, generally, forgiving and loose in their understanding. So many of the “bugs” and issues you have when solving a problem in your program originate in not being clear and explicit enough in your instructions.”
How can I apply the rubber duck debugging method?
These are the following steps:
- Beg, borrow, steal, buy, fabricate, or otherwise obtain a rubber duck (bathtub variety).
- Place rubber duck on desk. Inform it that you are just going to go over some code with it if that’s all right.
- Explain to the duck what your code is supposed to do. Then, go into detail and explain your code line by line.
- At some point, you will tell the duck what you are doing next. Then you’ll realize that that is not in fact what you are actually doing. The duck will sit there serenely, happy in the knowledge that it has helped you on your way.
(Extracted from rubberduckdebugging.com)
Where can I find my partner in crime?
Thankfully, rubber ducks are widely available. They are a valuable asset to any team so they can be easily found on various online stores. You can even create a personalized rubber duck or get one that looks like a celebrity here: https://celebriducks.com/
Are rubber ducks the only ones I can in this debugging method?
Well, contrary to the method’s name, you can actually use any inanimate object. Any toy or object that you feel you can talk to and verbally explain your struggles works. The main idea is to help gain more clarity on the problem and find the solution without having to wait after your colleagues until they are available to jump in and help.
Do I have to be a developer to team up with a rubber duck?
Now, contrary to the method’s definition, you don’t have to be a developer to use this debugging method. Regardless of the field you work in, explaining the flow and logic behind an idea can help you see potential improvements and solutions. It’s when you notice that you can’t find a solution using this method that you ask for help from a teammate.
If you’re looking for a solution, go ask the duck! Really, check out the Ask The Duck story to see how helpful this method can be when it comes to problem solving. While this method is already validated by lots of software developers out there, you can also check out Soumya’s take on this method here. She used the rubber duck while studying for her Computing and Information Systems exam (she’s a BSc Computing and Information Systems student at University of London), and talked about her experience with the rubber duck on the University’s blog. So, are you still looking for a solution to your problem? Did you ask the duck?