Today Iām going to show you one of the most effective methods of debugging for developers and software engineers. Rubber Duck Debugging.
If youāve ever been stuck trying to fix a bug or implement a new feature then you know why this matters so much.
Effective debugging is the difference between hours, day and weeks of pain and struggle.
Most people hit the proverbial wall and continue to bang their head against it till eventually the wall wins. It will always win.
They never step back and assess whether thereās alternatives to what theyāre doing or if they even understand the problem in the first place.
If youāre not feeling embarrassed while talking to the duck then youāre covering up your lack of understanding with technical lingo. Simplify.
Today weāre going to cover:
If you want to finally get past the inevitable wall then keeping reading.
Rubber duck debugging was first coined in the bookĀ The Pragmatic Programmer written by Andrew Hunt and David Thomas.
In the book they tell a story about a programmer who carries around a rubber duck and has to explain his code line by line to the duck.
Cute story but thereās more to it then that.
Rubber duck debugging can be extended from a simple line-by-line explanation into a full framework of critical thinking.
If you pair the line by line communication method with formulating a detailed question then you have the means to understand what the problem actually is and where the code actually breaks.
If you canāt communicate the questions in a clear and concise manner, avoiding as much technical jargon as possible, then you donāt understand the problem clearly enough yet.
It works well because stepping through your code line by line forces you to explain exactly what is happening.
Itās the thoroughness of the technique that makes it so powerful.
You step through even line and explain it as fully as you can.
You donāt skip over sections, you remove assumptions and you donāt go to the next line without understanding what is going on with each step.
This is how the computer runs the program so it makes sense to debug it that way.
Itās also really important to vocalise the line by line explanation out loud.
Not only will this help you improve your communication skills but the brain works differently when it has to put thoughts into articulated words.
Having a duck to debug with might sound silly but having a prop to talk to helps a lot because you have a recipient for your communication.
Youāll know if something doesnāt sound right when you try to verbalise it to the duck.
The rubber duck prop is a good one.
Itās fun, itās novel for the first few times when doing it and it gives you an external point of focus for communicating.
But even I know it feels weird to do and not everyone likes to debug this way by themselves where thereās no feedback.
So hereās some slight alternatives that elicit the same effect with different pros and cons.
Itās all about communication so using the same technique with another person listening is a natural alternative.
You can do this with someone you work with and other developers. They have the technical background to understand what youāre stepping through code wise but even better theyāll be able to debug your original question if it doesnāt make sense or if itās poorly phrased.
I find talking through some problems with my wife really helps. Sheās not a programmer and that helps because I have to think about how articulate the problem and how I can explain the code in the simplest terms possible.
Another great one is to use an AI tool. Although I havenāt found a good way to step through line by line with a AI tool they are really good for posing questions to.
If you write up your problem statement fully and ask AI to explain it back to it might reveal that your question has assumptions, gaps or too much technical jargon that you donāt fully understand yourself.
I refer back to this a lot but I find that walking really is the creative super power everyone needs in their day to day life.
Whenever Iām really stuck on something and rubber ducking is not enough I get up and walk around.
Breaking my eyes away from the screen for a little bit allows my mind the space to think without the code being in the way and I can think about it conceptually.
Sometimes Iāll walk around with the laptop so I can activate the powers of walking whilst stepping through the code line by line.
Now where can I find one of these fine instruments I hear you say?
Well, I actually have a couple of these incredibly cute and awesome Tubbz Gandalf Rubber Ducks.
I have both Gandalf the Grey and Gandalf the White.
Theyāre great quality and you can find all sorts of characters beautifully embodied by the Tubzz brand.
But obviously any old rubber duck/inanimate object will do.
This technique can save you a lot of time and really improve your communications skills in a real way.
Remember to go line by line, explain it simply, make no assumptions and form a well articulated question to improve your understanding of the problem.
Thanks again š
Sign up to my weekly newsletter for software engineers/developers that want to grow. I share my past successes and failures so you can get a head of the rest.