What does a computer programmer and a rubber duck have in common?
First things first, we haven’t lost our minds.
Solving a software debugging problem with a rubber duck really is a technique used by a lot of developers.
It doesn’t have to be a rubber duck though. There’s plenty of other names for this technique, often involving either an inanimate object, a puppy/kitten, small child or at a pinch a fellow coder… but our favourite will always be the humble rubber duck.
So how do you go about solving complex problems with nothing but your wits and a rubber duck?
There’s a big difference in how a human thinks to how a computer thinks.
When a programmer runs into a bit of a problem with their code, it’s more than likely because they’re looking at something differently to how a computer will.
Computers are precise, logical, and, seen from a certain perspective… quite inflexible. The counterpoint to that is the human brain which will be quite forgiving of someone explaining something to them, filling in the blanks where required from their own imagination or experience.
That’s why so many bugs a programmer has to deal with will come down to their instructions (code) not being quite precise enough.
But what about the rubber duck we hear you cry?
Rubber ducking (as it’s sometimes called – “Have you tried rubber ducking it?”) helps a programmer get round that problem.
The programmer knows the intent of the program, the computer doesn’t. Your rubber duck then, will help bridge that gap.
In essence, if a programmer hits a roadblock, they’ll explain what they’re trying to do, and the code they’re doing it with, line by line, to the rubber duck.
The process of having to slow down and explain what’s happening, line by line, to an object that knows nothing about programming, often helps the coder identify the problem pretty quickly by simultaneously explaining what it’s supposed to do and what it’s actually doing.
It also helps to change a programmers perspective somewhat as what they’re doing is actually ‘teaching’ the rubber duck, forcing them to view their code from a different angle and thereby offering a deeper understanding.
The use of the rubber duck also means this can be achieved without having to disturb anyone else… always a benefit when you’re trying to hunt down an embarrassing mistake or glitch in your code.
Now you know the theory, applying it to a practical method couldn’t be easier!
The reason rubber ducking works so well is that by following this process you’ll almost always find your problem, normally a small typo like a misplaced div – The duck always reveals something!
The reason rubber ducking works so well is that explaining something to someone else (in this case your faithful rubber duck) causes an actual shift in your thinking process.
The first thing to happen is that you’ll be forced to slow down and pay a lot more attention to what you’ve typed as most of us will think a lot faster than we can type (or code). Having to verbally explain what you're doing will likely make you a lot more accurate.
The second benefit to rubber ducking is that you’re forced to work to your rubber ducks level or knowledge of coding (and rubber ducks make awful coders… trust us).
Your rubber duck won’t know nearly as much about the problem as you do. Simplifying the problem to a level where a rubber duck can understand it will almost always reveal the solution.
Are you telling us your bathroom doesn’t already have a rubber duck you can ‘borrow’ to talk code with?
Never fear, they’re incredibly easy to buy online… but we still think there should’ve been one in your bathroom already!