The Rubber Duck Debugging – why does it work?

Programmation is a painful art. You are a real architect and you mission is to design, build, decorate and maintain an application, much like how you would do for a house.

One difficulty emerges though: you have to communicate information with a machine through programming languages to make everything work. Surely you don’t talk to your furnitures to place them into your house, right? Right?

This little difference is crucial, as you sometimes will encounter an issue that you have no idea why it is there. Truly you developed this thing so perfectly that it should not fail. But here we are, a bug is there and you don’t know why.

The first thing to do is of course to blame it on the computer. I mean, you know what you’re doing, there is no way you wrote something the wrong way. It’s probably this damn laptop which is making you look like a fool again. But the truth is hard to swallow.

The machine does exactly what you tell it to do.

Bill Gates, probably

Like it or not, your computer is dumb. It will mindlessly retrieve the information you provided and execute them. And if it fails, it is, without a doubt, your fault. I know the pain, trust me. But don’t worry too much, it happened to every one of us, and at the end of the day, everything will be fine.

Now, it is all up to you. You know that you did something wrong, yet are unable to find what.So what’s next? Should look up answers on StackOverflow? Resign of your position as you clearly are not good enough for this job? The answer is simple.

The first step when you are stuck, is to ask the wisdom of the duck.

I know what you’re thinking right now: What are you smoking and where can I get some? But trust me, this whole duck thing is not an hallucination, it is THE best way to help you.

Don’t worry though, you won’t need to drive to the nearest farm and steal a duck to apply this advice. In our case, a rubber duck is what we need.

Once you get your hands on one and place it on your desk, the only thing left is to talk to him. Go ahead, don’t be shy and explain to him what’s happening with your code.

I’d rather tell about it right now so you don’t end up shocked when confronted with the truth, but the duck will not respond to you. Hearth-breaking, I know. However, he is the perfect listener and his patience is way above any other human being unlike your co-workers. Moreover, the duck will never judge your mistakes. He is kind and comprehensive.

And the more you will explain to him your troubles, the more you’ll realise what was wrong all along in your code. Indeed, trying to explain properly to the duck what you are trying to do will expose a tiny inconsistency between what you did and what you are trying to achieve. Slowly but surely, you will soon enough be able to pinpoint the exact line of code that was causing all your troubles and fix it like the pro you are.

And that’s why the duck is so useful. Not only did you let your coworkers work in peace, this exercice forces you to take a step back at your code so that you can explain it to someone who has no clue of what’s going on.

This effort to put words on the expected behaviour and what you were able to achieve for now will highlight any potential mistakes you might have made during the development, things that can’t be seen when you spent eight hours looking at your code non-stop.

In describing what the code is supposed to do and observing what it actually does, any incongruity between these two becomes apparent.

Stephen J. Baker

So next time you’re stuck on something, don’t bother your co-workers, save your internet data and simply ask the duck!

If you wish to learn more on this method, I strongly suggest having a look at the website behind this post’s inspiration.

Leave a Reply

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