The Rubber Duck Debugging
Tags: webdev, beginners, programming, coding
Published: 2024-05-13 21:20:31

Having bugs in your code is a universal problem that beginners and experienced programmers encounter when writing code. Bugs are errors in your code.

When programmers encounter bugs in their code, there first points of call were Google, question-and-answer websites like[ Stack Overflow](https://stackoverflow.com/) and [reddit](https://www.reddit.com/), and now [chatgpt](https://chat.openai.com/). But there is a technique that programmers have been using for decades when they have bugs in their code. The technique is called rubber duck debugging.

The rubber duck debugging is a technique that programmers employ by explaining your code line by line to a rubber duck.

In this article, I'll take you through the debugging technique that programmers use to debug their code. After reading about the technique, you can apply it in your code when next you encounter bugs in your program.

### What is Rubber Duck Debugging and Where Did the Term Come From?

The concept of rubber duck debugging was introduced by Andrew Hunt and David Thomas in their book, [The Programmatic Programmer](https://pragprog.com/titles/tpp20/the-pragmatic-programmer-20th-anniversary-edition/) in 1999.

The rubber duck debugging is a reference to a story in the book, The Programmatic Programmer, about a programmer who carries a rubber duck around to debug their code by explaining the code line by line to the duck.

The idea behind the rubber duck debugging is that, there are times that when you're coding, you might not have friends to consult when you encounter bugs in your code, or you're have problems to solve. By talking to a duck or any other inanimate object about your problem, you're likely to hear illogical thought process in the step by step instructions in your program. This will reveal what you've been doing wrong or reveal the bugs in your code. 

By explaining the lines of code to a duck by talking, the programmer was able to debug the errors in the code, execute it and run the code successfully.

During this technique of meticulous explanation of every line of code to a rubber duck, you might encounter the bugs that render your code from running.

Although the duck can't reply or engage you to solve your problem, yet, by explaining the problems to the duck line by line, the functions, loops, or variables, you may be aware of where things go wrong. In the process of doing this, the bugs might be that you omitted a semicolon at the end of a statement, a typo error,  or the closing bracket was omitted.

The rubber duck allows you to explain your problem line by line and your goals to the duck.

###  Rubber duck debugging: A step-by-step guide

- Buy a rubber duck (or an inanimate object) and place it on a desk.

- Explain your goals , and explain your code line by line to the duck.

- During the explanations of your code, your thought process might reveal where things go wrong.

### Final Thoughts

Rubber duck debugging is popular among programmers. They see it as a technique that aids programmers in their thought process.

You might as well buy a rubber duck and put it on your desk. When next time you encounter a bug, you can apply the rubber duck debugging technique to compliment and aid in eliminating the bugs in your code.