Rubber Duck Debugging

One of my favorite code debugging methods

Kristina Mancini
3 min readMay 9, 2023

I found one of those stink bugs on my kitchen windowsill the other day.

I took a cup and swiftly surrounded the small fellow in the plastic enclosure, capturing it. Then, I slid an envelope from underneath so I could lift up the creature with ease. Afterwards, I set it free into the wild, successfully debugging my kitchen (of stink bugs, I hope).

Debugging is pretty helpful, not only for bugs in your kitchen but also in computer programming.

Debugging

Debugging is a process that helps you find an error and deletes the error in your code. Just like finding a bug in your kitchen that you did not invite in!

There are some debugging methods such as print debugging and wolf fence debugging, but the method I really wanted to write about was rubber duck debugging.

Last week, I studied the Software Development Life Cycle and came across the rubber duck debugging method. I knew I wanted to research it more because the name caught my attention…and I think ducks are pretty cool.

The Rubber Duck Debugging Method

A method of debugging that uses one of those little rubber ducks you put in your bathtub. This little guy:

a rubber duck with sunglasses on, sailing through a pond
Photo by Susan Weber on Unsplash

Here’s the gist of it: the programmer puts the duck on their desk and explains each line of code to the duck in order to discover any hidden errors found in their code.

As for the history of it, the method can be found in the book, “The Pragmatic Programmer” by Andrew Hunt and David Thomas. It was a story in the book that depicted a programmer who carried this rubber duck around and explained their code to it for help in debugging.

Why it helps

Explaining your code, line by line, to a rubber duck that knows nothing about programming makes you have to explain it in a simple and understandable way. It slows down the process of searching through blocks and blocks of code, helping you think and focus more on each line. Then, you can catch mistakes and possibly improve something in your code that you did not realize before.

And that may be the psychology part of it kicking in. This might just be me but explaining something in simpler terms to someone else helps me remember more information and keeps me confident in what I am learning, almost like teaching a subject helps you remember it more.

Ever since I learned of the rubber duck debugging method, I’ve found myself using it not only in programming but also in everyday things like running errands or planning a future goal. (Is that weird? I hope not.)

If you are ever feeling stumped with your code, another project, or maybe even in life (this turned philosophical so quickly), go get a rubber duck and talk to it. It might even help you make a sudden discovery.

And I can happily say, I proofread this blog post with a rubber duck on my desk!

Sources:

3.5 Common Debugging Methods. (2021, August 23). OpenDSA. Retrieved May 9, 2023, from https://opendsa-server.cs.vt.edu/ODSA/Books/Everything/html/debugmethods.html

Kenzie Academy. (2020, November 16). What is Rubber Duck Debugging? Southern New Hampshire University. https://kenzie.snhu.edu/blog/what-is-rubber-duck-debugging/

Rubber Ducky Debugger. (n.d.). Paul G. Allen School of Computer Science & Engineering University of Washington. Retrieved May 9, 2023, from https://courses.cs.washington.edu/courses/cse154/cp/19sp/cp2/banana-gun/index.html

--

--

Kristina Mancini

I write about different topics in computer science and technology.