Photos_ImagesRubberDuck

The rubber duck debugging method or the art of solving a problem when you’re a programmer.

When you write code for software, if there’s one thing a programmer knows for sure, it’s that at some point it will get stuck. This happens all the time, and any programmer can tell you that. No matter how much experience you have, whether you are a beginner or a veteran, you will find yourself at a dead end with a programming problem that you can’t solve right away. The question to ask yourself in such situations is: how do you solve the problem? One of the most popular techniques is called Rubber Duck Debugging.

 

shutterstock_313815854_550

 

What is Rubber Duck Debugging?

The Rubber duck debugging methodology, also known “rubber ducking”, is the process of explaining a programming problem to a plastic duck in a meticulous manner and out loud. This exercise highlights inconsistencies and solves the programming problem.

Let’s take the following example. You write an algorithm and your line of code doesn’t work. The piece of code you just wrote has an inconsistency and does not respond in the way you would have imagined. What do you do? You try to find a solution on your own, without much success. Then you get up from your desk, go to your friend-colleague who is also a programmer for the same company and start explaining your situation so that he can help you. You explain what you’re working on and then all of a sudden, it hits you, the solution is obvious!

“You’ve all heard the line: asking the question is the answer. This is even truer when we try to explain our code. When someone explains their code to you and says something like “don’t pay attention to that, it’s just to make it work in the meantime…” or “this method is supposed to do this or that”, chances are it’s hiding a problem. Another example, when you’re told, “I don’t really know what this does, so I didn’t touch it”, that’s a big red flag. Don’t take for granted that what you’re told is true, you should always check it out. ”Éric De Carufel – Director of Technologies and Partner at Done Technologies

As simple as it may sound, it is very common for programmers to find themselves in this kind of situation: they face an inconsistency in their code, go for help and the solution suddenly appears to them. Simply expressing your problem out loud and talking to a colleague can help you solve the problem situation. This is called the rubber duck method.

shutterstock_1506835145_750x229

Why the rubber duck?

The idea of talking to a rubber duck comes from the book The Pragmatic Programmer: From journeyman to Master by Andrew Hunt and David Thomas, in which a student explains his code line by line to a rubber duck for easier debugging.

Since the publication of this book, it has been very common to see this little plastic animal on programmers’ desktops, so much so that over time it has become an iconic figure in the world of programmers and developers. Using the rubber duck allows you to reproduce the same exercise (without having to disturb one of your colleagues), in addition to offering unlimited attention and listening.

Why does the Rubber Duck Debugging method work?

The reason is simple, when you explain your situation to someone else, or in this case to a rubber duck, you are obliged to explain the problem in detail to the person you are talking to. You explain the context, each of the steps and lines of code, and then you finally get to the bottom of your problem. It is by doing this process that the solution appears to you in a logical way. In other words, what you’ve just done is to take a break, step back and you’ve gone through the film in your head.

By doing so, you have a better visualization of the situation. When you explain your problem to a rubber duck, it doesn’t know anything about the code (it’s a duck) and so you have to explain your problem to it, put it in context. And that’s how by explaining your project from the beginning in the smallest details, going step by step, up to the problematic situation, you will find by yourself the answer to your problem. When we work several hours on the same project, we tend to be too “involved” and when a problem or inconsistency arises, all our attention is focused on it. By taking a step back, the solution becomes more obvious.

Do you have problems that need help or advice? Our software architecture support service will help you in your projects. It is a kind of online Rubber Duck Debugging service with a team of experts at your disposal.

Want to share your experience and stories where the Rubber Duck methodology has really helped you? Share your comments below!

 

Leave a Reply

Your email address will not be published. Required fields are marked *