You may have heard the phrase, or perhaps seen a meme or two about “rubber duck debugging”. But what exactly is rubber duck debugging? Now this may sound ridiculous when you first read this, but rubber duck debugging is the process of debugging code by explaining it to a rubber duck. Yes, you read that right. That may seem absolutely crazy… talking to a rubber duck, but it absolutely works!
To help it make more sense, the process is really about being able to articulate a problem in plain english (or whatever language you may speak), and not in code. The magic behind the process is that in the act of explaining what the code is supposed to do, it often becomes apparent what the difference is between intended function and actual function. It often helps to use as non-technical language as possible, as if you’re explaining the code to a non-programmer (or a rubber duck). It is a well studied and understood psychological phenomenon that teaching a subject can help reinforce the subject at hand, and even lead to the teacher arriving upon a greater understanding of said subject. You can read more about the psychology behind rubber duck debugging here.
Ultimately the duck is optional. Some people chose to use other inanimate objects, or pets, fellow engineers, or even someone in their life that doesn’t understand code. If talking to a rubber duck or your cat is just a bit too crazy for you, there is always the option of just talking to yourself. While the act of explaining code in an attempt to figure out why it isn’t currently working as intended likely has many origins, the term “rubber duck debugging” comes from an anecdote provided in the book “The Pragmatic Programmer” (updated 20th anniversary edition can be found here, I highly recommend it).
So the next time you’re stuck debugging some code and just can’t figure it out no matter what you do, take a cue from Ernie and have a heart to heart with a ducky. You’ll be surprised at the insight the little rubber fellow can provide.