Sometimes when you’ve been working on a piece of code for a long time, all of a sudden you spot a bug that needs to be solved to continue. Whenever you can’t seem to figure out what causes the bug, there is a useful trick you can use to get to the solution: Rubber Duck Debugging.
What is debugging?
Debugging literally means removing the bugs. Whenever you right code, it doesn’t always work as you expect it. Sometime you won’t know until an “edge-case” has happened. For example, someone makes a combination in the blog-filter that you did not account for, resulting into the page being stuck. This is not how the code was intended to work, so it’s considered a bug. “Removing” a bug usually means adding or changing code, so the same error won’t happen again. Finding the code that causes the bug is a big part of the debugging process.
Here’s the thing: finding a bug is not always as easy as you hope it would be, not even in code you’ve written yourself. You did not deliberately put the bug in the code yourself, so there is not always an obvious spot where the code is faulty. Sometimes you find it within 10 minutes, sometimes it takes you hours to figure it out. It might be hard to believe, but a rubber duck helps!
Why does a rubber duck help?
Let be be honest: it doesn’t have to be a rubber duck specifically. Any object, person or even nothing at all works for this, because it’s the idea behind it. Let me explain: When you are stuck and haven’t found the cause of the bug yet, set your rubber duck on your desk and explain the entire challenge you’re facing. The duck just stares at you, but stays silent. Yet at some point during your explanation, you realize you are listing all the assumptions you are making that you will have to double check.
The point is, all you needed to do is layout the problem. It brings your attention to each detail and this often ends up in you finding the cause, bringing you one step closer to the solution. A rubber duck can be a visual reminder of this, or you could just actually talk to a rubber duck, no worries, you won’t look crazy 😉
Debugging non-code issues
You’re maybe not even a programmer, so why am I telling you this? You can actually debug non-code issues! I’ll give you the classic example that I always give anyone that asks about rubber duck debugging:
Imaging losing your keys. Tell your rubber duck the entire story, from the moment you last remember using your keys, to the first moment you found out you lost them. While you list all the places you’ve been to since you’ve last used your keys, you’ll probably list the place where your keys are at. Go check them!