Rubber Duck Debugging


Last updated: 24th August 2017

2 min read

It sounds crazy, right? A rubber duck is the perfect debugging partner. It has no arms or legs and sure as hell can't read or write code. So how can our little yellow friend help us write better code? Today we're going to learn about Rubber Duck Debugging.

Let's take a step back for a second. Programming is hard. If you're reading this you know that. You're also human, probably. Humans make mistakes. Writing bugs is just part of being a programmer and when you get stuck on a bug, sometimes all you need is a rubber duck.

Debugging with your duck

So how do we debug code with a duck? Well, it's pretty simple. First, you get yourself a rubber duck. Next, you set your rubber duck next to your computer and finally, you verbally explain to your duck what each line of your code does.

I find this process incredibly helpful. Almost always, when I describe what my code does using plain language, it becomes very clear what is going wrong.

Why it works

It's a well documented fact that explaining a problem or challenge with spoken words forces you to slow down and be more analytical with your description. It might sound crazy, but you don't always know what you're going to say, you might surprise yourself.

This technique can be applied to all kinds of problems but works particularly well when you are explaining code. By talking about each line of code, you challenge your own assumptions of what it does. I'm sure you've heard that the best way to learn something is to teach it to someone else. Well, this is essentially the same thing.

Conclusion

Next time you get stuck on a bug, instead of calling over your colleague, start talking to your rubber duck. Your colleague will be thankful! By using the rubber duck technique, I've learned to take my time when writing code. I've become better at debugging and I've become better and explaining myself and my code.

Subscribe to my newsletter

I'll email you about tech, what I'm working on, and other interesting things I find around the web. I'll never spam you and I won't share your email with anyone else.