Curated by: Sergio A. Martínez
Debugging software is an important, if often tedious, the task for any programmer. Finding and removing errors generating crashes, freezes, or incorrect results is critical to ensuring the quality of a piece of software, and while some bugs can be fixed with a few simple tests, more difficult ones require special approaches and techniques. And thankfully, there are many resources available to help programmers debug their software; after all, with patience and perseverance, even the most difficult bugs can be squashed.
One such technique is the popular Rubber Duck method, which may already be familiar to a seasoned developer. In short, the Rubber Duck method is a debugging approach in which developers explain their code line by line to an inanimate object, such as a rubber duck. This may sound silly, but it’s an incredibly effective way to find and fix mistakes.
“Computers process information differently than humans do. Anyone who’s first learning to program understands this well. What’s hard about programming for a beginner isn’t really big hard esoteric concepts, but that you’ve got to be so painfully exacting in how you describe everything to a (dumb) computer. That’s why we do rubber duck debugging.”
However, have you ever been curious about why this approach works? What exactly happens in our brains when we verbalize a problem to someone else (even if that someone just happens to be a bath toy), that could lead to a solution that was obvious all along? And what is the best way to implement this method to finally find and solve that bug that has been bothering you all week?
The challenge of language
Computers are dumb. And we don’t mean that in a Luddite, anti-tech sort of way, we mean it in the original definition of “dumb”: incapable of human speech. And speech here is more than just talking; speech includes context, mood, choice of words, familiarity, and an infinity of other variables that a computer can’t understand (yet).
Of course, this doesn’t mean that we cannot communicate with computers, it just means that we use specialized languages to do so, and every single one of them works with the principle that computers are dumb: unless you tell a machine exactly what they need it to do, or how to react when something happens, they will not produce a desirable outcome. Thoughtful Code put it best:
“‘Is it cold outside?’ is a question that most humans, having some idea of the weather, will answer pretty easily. They’ll say something like, “No, it’s pretty nice.” Asked that question, a computer — or a really finicky and hyper-rational person — will need you to define each of those words.”
A computer understands the most literal and absolute terms and learning to manipulate those terms is the basic principle of programming. This also means that computers don’t make mistakes, people do. So, if something within the instructions given to the machine doesn’t add up, then the program will not work as intended, and finding the exact place where the communication between a person and a computer got out of alignment can be a challenge. Here’s where the rubber duck comes in handy, thanks to the way we process language.
Here’s a fun fact: did you know that reading, writing, and speaking are located in completely different parts of our brain? Our understanding of the way we use and apply language is always evolving, but it is understood that we use different functions depending on the type of language we employ, which is why it’s so useful to verbalize a problem to find a solution: you involve a completely different part of your mind to help.
Of course, the Rubber Duck method is not useful only in software development, but since computers are very linguistically complex tools (being probably the only ones we need to “speak to” to use), verbalization is useful here, forcing developers to slow down and think about the minute details of their code, which can help to spot mistakes that they would otherwise overlook. As the blog “The Psychology Behind Rubber Duck Debugging” puts it:
“A lot of times, I’ve experienced some programmers that will ask my help about a specific bug they are fixing. I will then ask them how their application and their code works. I literally have no idea how to fix a program that is not mine and have no idea about the flow. However, I let them explain the flow of the process and the connection between functions and files. Oftentimes, they think of a solution before I even understand what is happening. Many people have been so thankful for me — for doing literally, nothing.”
Programmers understanding themselves
You can see the same principle at work in the classroom. Teachers probing students with questions are intended to make sure a lesson has been learned, forcing the students to consider and explain it by themselves. The only difference is that a programmer using the Rubber Duck method is taking both roles (teacher and student) at once.
In other words, this method allows developers to share their thoughts with a neutral party, questioning and probing themselves regarding their code, which can help identify areas of confusion or misunderstanding. And most importantly, it encourages developers to develop a clear and concise explanation of their code, which can be useful for future reference.
“The real magic doesn’t happen on the rubber duck itself (sorry, Duck Norris). However, it happens in our minds. It uses the same psychological principle wherein we are encouraged to explain to ourselves why we did such actions and have a self-realization about what we’ve done. It is usually used by most psychologists to fully understand a person and, at the same time, for the person to understand himself/herself fully.”
And understanding yourself is fundamental to being a good programmer. Just like writing any other thing (a novel, or a sheet of music), everyone has their own style, approach, and technique when coding an application, which makes the ability to explain what you wrote so important; if you aren’t able to understand your process inside and out, then debugging will always be a challenge, especially when working as part of a team, where the code must always be in sync. In fact, the Rubber Duck method can be used as a form of collaboration, as another programmer can serve as your rubber duck and offer feedback or suggestions while you go through your code trying to find an answer.
“When working on a software development project, it’s important to have a good collaboration method in place, and the rubber duck method is one way to ensure that everyone on the team is on the same page”, says Jesús Magaña, Senior Project Manager at Scio. “It can help a developer to articulate his or her thought process, and as a result, team members can quickly identify any gaps in understanding and address them before they cause problems. Additionally, the rubber duck method can help to uncover errors in logic or coding syntax, and overall is an effective way to ensure that everyone on the team can contribute.”
In a Nearshore development environment, where collaboration has come a long way in recent years, the Rubber Duck method can also be useful to bring keep everyone on the same page by improving communication, helping maintain contributions clear, and easing the challenge of solving a tough bug even in remote settings (where a developer may not have anyone to immediately bounce ideas or solutions during debugging), which can help projects to come together more easily. After all, Nearshore software development has its challenges, but by using the proper approach (or bath toy), teams can overcome obstacles and build better software together.
The Key Takeaways
- A bug in the code is basically a mistake in communication between a developer and a computer.
- Following this, it’s no wonder that approaches to problem-solving like the Rubber Duck method can help to find the precise place where a code is not working.
- Although you only need something to talk to (like a rubber duck), this process can involve many people in a team, offering advice and feedback.
- However, in remote setups (like with a Nearshore development partner), having a way to find and fix bugs without the insight of anyone else can be a valuable resource.
Scio is a Nearshore software development company based in Mexico where we believe that everyone deserves everyone should have the opportunity to work in an environment where they feel like a part of something. A place to excel and unlock their full potential which is the best approach to create a better world. We have been collaborating with US-based clients since 2003, solving challenging programming puzzles, and in the process showcasing the skills of Latin American Engineers. Want to be part of Scio? Get in contact today!