Rubber Duck Debugging: How a rubber duck helps solve your complex problems
Rubber Duck Debugging may be an unfamiliar concept to many, but at Cube, it’s certainly not the case. If you take a walk through the office, one desk stands out in particular: Jordy’s, Cube’s Tech Lead. Why? Because there are rubber ducks everywhere on his desk! This colorful collection naturally raises questions, and that’s exactly what inspired this blog. While they may seem like cute decorations, these ducks actually have a surprisingly important function: they help solve technical problems.
What is Rubber Duck Debugging?
As a programmer or developer, you often encounter problems that are difficult to solve. Sometimes you think you're stuck, until you start talking -to a rubber duck! This phenomenon, known as Rubber Duck Debugging, is a surprisingly simple yet effective method of organising your thoughts and solving problems on your own. While it may sound simple, there is more to this technique than meets the eye.
Rubber Duck Debugging revolves around the principle that by verbalising a problem out loud, you often arrive at the solution. The name comes from The Pragmatic Programmer, in which a developer had a rubber duck on his desk and explained his code to the duck line by line to find bugs. Organising your thoughts and giving a step-by-step explanation often reveals where the error is.
It doesn't necessarily have to be a rubber duck; any object can serve as your 'listener'. For example, you can use a coffee mug or even your cat. It works because it forces you to review your problem in a structured way, which often leads to new insights.
The power of talking out loud.
The essence of Rubber Duck Debugging lies in the psychological effect of explaining your problem out loud. Many developers have found that when they explain a problem to someone (even someone with no technical background) they often arrive at the solution themselves. This is because speaking your thoughts out loud forces you to think about the logic of each step in your code.
A practical example.
Jordy has been using Rubber Duck Debugging for years, a recent example of his illustrates perfectly how powerful this method can be. He needed to temporarily put an application into maintenance mode to allow the customer to perform a migration in peace, without affecting users. While explaining his plan to his trusty rubber duck, an important question arose: "But will the customer still be able to log in themselves?"
Thanks to this 'conversation', Jordy realised that he needed to make an exception so that the customer would continue to have access, while other users could see the maintenance page. That simple question from the rubber duck made for a smarter solution and avoided a potential problem.
How does it work?
The idea behind Rubber Duck Debugging is that by describing what your code should do and comparing it to what actually happens, you often discover inconsistencies. Speaking each step out loud helps avoid blind spots. This process provides a renewed perspective and breaks fixed patterns of thinking, making your brain look at the problem in a new way.
Jordy now has a rubber duck tradition of his own. "At every screen I have a rubber duck," he says. "It reminds me to occasionally go through my issues and processes. My oldest rubber duck is now four years old and the collection keeps growing thanks to friends and colleagues. The nice thing is that rubber ducks come in all kinds of themes these days!"
Everyone is already doing it.
Although it is known in the programming world as Rubber Duck Debugging, we all use some form of this technique without realising it. Just think of the times you have said out loud, "Where did I leave my keys?" You start repeating your steps and talk yourself through the problem. The same principle applies in the programming world: by verbalising your problem out loud, you force yourself to revise your logic and you often discover the error, or in another case, where your keys are, more quickly.
When you apply this technique with a human instead of an object, we call it confessional programming. This happens when you ask a colleague or friend to listen while you explain your problem. The solution often seems to emerge automatically without the other person having to say anything. The social pressure to be clear can work even better than talking to an object. Asking a 'simple' question can lead to a great idea or innovation, as here at Elon Musk.
How do you apply Rubber Duck Debugging?
Pick an object: Whether it is a rubber duck, a coffee mug or a tangerine, any object can be your listener.
Explain the problem step by step: Describe in detail what you are trying to do and what is going wrong. Don't skip anything, even if it seems obvious.
Do it out loud:By speaking your thoughts out loud, you activate other parts of your brain.
Be patient and honest:Sometimes it takes you a while to get to the solution, but by fully articulating the problem, you will get a better understanding of what is going wrong.
Consider every aspect:Don't just look at the output of your code, but also ask yourself questions like, "Why do I think this should work?" This helps identify blind spots.
The impact of Rubber Duck Debugging.
Rubber Duck Debugging is more than just a funny anecdote. It is a valuable tool that helps you break through problems. Whether you are a beginner or an experienced programmer, this technique can help you reach solutions faster and look at your code with new eyes. So, next time you get stuck, grab your rubber duck, start talking and discover for yourself the power of Rubber Duck Debugging.
Ready for the next step? We are too.
Want to know more about Rubber Duck Debugging? Jordy is happy to talk to you!
Worth reading next...
Cube X Fundaments
Successful internal digital transformation with a Knowledge Base.