Rubber Duck, the code debugging method

Software programmers can get stuck for hours or even days trying to fix code errors. Programmers use rubber ducks to make their work easier. Although the ducks do nothing on their own, it turned out that explaining the code would help the programmer find the problem. Once you try to explain the problem to someone or something else, you will understand better and find it easier to find a fix.

What is rubber duckling?

Rubber duckling is an abbreviated term for "rubber duck tuning", which is a code tuning method that includes a classic bathroom toy. And how did the rubber duck get into the software? Andrew Hunt and David Thomas describe the story of The Book of the Programmer Programmer, where a programmer debugs code by explaining it line by line aloud to a rubber duck. As you explain, you'll probably find pieces of code that don't do what you thought they did or that need to be fixed. A rubber duckling is about going through coding problems with a friendly duck that doesn't judge you.

What makes a rubber duck effective?

If you explain something out loud, your thinking will slow down. Human brains can process up to 350 to 500 unspoken words per minute, for example when reading. However, we may tend to express ourselves around 120-180 words per minute. When we explain something out loud, it forces us to slow it down and spend more time considering what we are saying.

We need to analyze each piece of code until we find a bug. The duck friend wants to hear every line and every detail, so we go through the codes with a fine-toothed comb to catch mistakes. When you assume ignorance of your rubber duck, you need to explain more thoroughly and accurately than you probably thought these specific lines of code were in your head. You are forced to be precise and help someone else understand your problem, to pay all the attention you used to take for granted very carefully. Computers don't think like humans, but they need everything down to the last detail, just like a rubber duck. At the same time, it means that you are forced to think like a computer, and therefore you encounter an error.

Why should we choose a rubber duckling before other tuning methods?

You will get a better overview of your code and your goals. When you talk to the code using a duck, you return to the destination of the code. Besides, the rubber duckling will allow you to solve the problem yourself, and thanks to this you will get the opportunity to learn from your mistakes. At the same time, you will feel more confident in your coder skills.

Errors are common in coding. However, it is not necessary to disturb your colleagues, because no one would do anything else. You also don't have to worry about being judged for not being able to solve this problem yourself. It's easier to be more open about discussing your mistakes with a duck friend who will never think of you.

They probably don't have the latest know-how, but rubber ducks will help you fine-tune your code. The next time you have a problem with your code, grab a plastic duck, and see how it works for you. It turns out that rubber ducks can be more than just a bath toy and a fun phrase.

Reviews (0)
Comment share