How To Debug Something With A Rubber Duck

How To Debug Something With A Rubber Duck

Published 06/07/22 under:

The Kerv Digital development team is adept at tailoring our clients business applications to suit their needs, and they’re always excited to develop new custom solutions to solve problems in innovative ways.

Sometimes, though, even the most experienced developers hit a roadblock. In this post, we explain a popular method of getting un-stuck that our team rely on day-to-day: rubber duck debugging.

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.

What Is Rubber Duck Debugging?

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.

Business Applications at Kerv

Empowering Your Business with Scalable, Intelligent, and Efficient Software.

Learn more

How To Rubber Duck Debug

Now you know the theory, applying it to a practical method couldn’t be easier!

  • Step One – Beg, borrow, build or steal a rubber duck from somewhere – The default yellow variety is fine but let’s be honest, if you’re going to be talking to a rubber duck, then the more outlandish the better.
  • Step Two – Place said rubber duck somewhere prominent on your desk – Feel free to put it in a glass case you can break in case of emergencies (depending on how often you have to check your code anyway).
  • Step Three – Upon encountering a problem, explain to your duck what it is your trying to achieve then walk it through your code a line at a time – don’t skip any details, rubber ducks love details.
  • Step Four – Enjoy your moment of revelation as you explain to the rubber duck what you’re doing and realise that isn’t what you’re doing after all.
  • Step Five – Quickly explain to all your colleagues you haven’t gone insane.

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 Psychology Behind Rubber Duck Debugging

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.

Where Can I Get My Own Rubber Duck?

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!

At Kerv, we’re passionate about getting the very best our of our team and supporting them to develop in their careers, whether that’s through a culture centred on flexibility and wellness, or in this case, an office full of rubber ducks.

To find out more about life at Kerv, check our careers section.

Have a question?

Leave your details and a member of the team will be in touch to help.

"*" indicates required fields

By pressing send, you agree to our Terms and Conditions and Privacy Policy.
This field is for validation purposes and should be left unchanged.

Explore all our upcoming events! View all

Worth Digital

is now part of Kerv

In a continued effort to ensure we offer our customers the very best in knowledge and skills, Kerv has acquired Worth Digital.