February 24, 2021

Rubber Duck Debugging

I recently came across this interesting debugging technique named 'Rubber Duck Debugging'. The name is a reference from the book 'The Pragmatic Programmer' by Andrew Hunt and David Thomas, in which a programmer is able to debug a code by explaining it line-by-line, to a rubber duck.

Though this was not exactly an 'Aha! effect' for me, it did set some curious nerve tingling, prompting me to read on and ponder over it.

“A very simple but particularly useful technique for finding the cause of a problem is simply to explain it to someone else… They do not need to say a word: the simple act of explaining, step by step, what the code is supposed to do often causes the problem to leap off the screen and announce itself.”

Verbalizing our assumptions, forces an evaluation from different perspectives and can provide a deeper understanding of the problem because it forces us to pay attention to detail. As a result, we may immediately gain some new insight into the problem.

So is the case with teaching a subject. Teaching a concept to another person (or even "the Rubber Duck") is one of the most effective ways to grasp it. One may then say, "a coworker might be able to substitute for the duck". However, many a times teaching a rubber duck may be more useful than explaining to a colleague, because suggestions from a colleague may lead to distractions or digressions, making it harder to solve the problem. Hence, the 'Rubber Duck'.

The technique touches on the cognitive science behind this phenomenon. When we think to ourselves, our brain is locked in a symbolic representation mode of thinking and uses only single sets of neural pathways and neural processes. This tends to keep us in a repetitive mode, leading us into a loop. Instead, if we actually say it out loud, this activates entirely different regions of the brain, taking totally different pathways. So, saying something out loud is more impactful than just running it over in the head.

Evaluating from different perspectives gives us a better/deeper understanding. This is why, when we’re trying to learn something difficult or complex, activating as many different neural pathways as we possibly can, helps strengthen memory and establish connection with the concept. This is why hand-writing notes is more effective than just simply listening or typing them.

And this brings us back to the Rubber Duck Debugging concept (or simply, Rubber Ducking)! By explaining things out loud, we’re not only using different sets of pathways and processes in the brain, but also filling in the gaps in our reasoning and assumptions. Thus the act of explaining the problem step by step, to the 'Duck', makes the solution present itself. The concept can be extrapolated and applied to other tasks such as revising for exams, preparing presentations and editing essays. Reading an essay out loud, for instance, can help one decide whether the sentences are grammatically correct and whether the essay flows well.

Here's to teaching rubber ducks!


No comments:

Post a Comment