What is “Rubber Ducking?” The phrase was made famous by Andrew Hunt and David Thomas in the book The Pragmatic Programmer: From Journeyman to Master. A book, by the way, which is required reading for all coders. In fact, it is time I reread it. You may already be familiar with this term, but in a nutshell, the idea is that simply explaining a problem aloud often helps one come up with a solution on their own. In the words of the Pragmatic Programmer,
Place a rubber duck on your monitor and describe your problems to it. There’s something magical about stating your problems aloud that makes the solution more clear.
This is an effective approach to problem solving. I’ve actually had a duck work by my side for years now. He’s a good, patient, loyal duck. Of course, you don’t need a rubber duck. Some people use email. In the process of meticulously documenting their problem, which will ultimately be shipped to all the smartest people they know looking for help, the solution comes to them. Some people call a colleague into their office, point at the screen and say, “I’d like to get a second pair of eyes on this.” The request for review comes along with a detailed overview of the problem which, in turn, begets an answer to one’s own question. As they say in the book, it’s magical.I stumbled upon an Interview with Hunt and Thomas which tells a bit more about rubber ducking. It’s a quick read and it’s worth a look.
Reading your source code aloud, or explaining it to someone else, has concrete and documented value, whether in a formal setting of code inspections, peer reviews or just chatting with your cube neighbor, said Thomas. “Have you ever done this? You stare at a piece of code for an hour, debug and debug, and finally, in desperation, you pull your friend in from his cubicle. You start to explain the code and how it works, but then â€¦” (smacking his forehead) “Oh, that’s it!”The audience laughed again, and most of them were nodding ruefully. In fact, Thomas said, you can even resort to “rubber-ducking.” “I don’t know why it works, but it works. You put the rubber duck on top of your monitor. Then, when you’re stuck on something, you start explaining what the code does aloud to the duck.” And before you’ve finished the explanation, the solution comes to you. You smack your forehead, and politely thank the duck, he said to general laughter.
Why do I bring this up? I am currently on a 6-week leave of absence from work spending time with my wife and new born son. Prior to leaving the office a few weeks back, I dropped my duck off on a colleague’s desk without any advanced warning that a duck-sitter was needed. I know the sentiment was appreciated, but I’m not positive the significance was understood. As I mentioned earlier, you don’t need a rubber duck. All you need is to willingly share your problems aloud. I was this person’s rubber duck. They always came up with the answers on their own, but not before giving me the opportunity to listen.
I hope my duck is getting an earful right now…
* Update: Previously, I incorrectly credited Hunt and Thomas with coming up with the phrase “Rubber Ducking.” In fact, it was Greg Pugh who coined the term. Thanks to Ed Davies and his considerate comment for addressing my oversight.