DEV Community

Cover image for Rubber duck debugging doesn't need to involve a duck!

Rubber duck debugging doesn't need to involve a duck!

Cover image credit: https://www.pexels.com/photo/yellow-duckies-in-line-on-a-concrete-floor-106144/

What is Rubber Duck Debugging?

Rubber Duck Debugging (or Rubber Ducking) is explaining to an inanimate object what your problem is, and in doing so finding a solution. Typically rubber ducks are used, but any inanimate object will do; my current rubber duck is a giraffe called Stumps!

A good rubber duck doesn't have to be a duck!

How to Rubber Duck Debug:

  1. You get suck in your coding and you can't find the solution.
  2. Take a deep breath to calm yourself.
  3. Find a duck, giraffe, monkey, or other inanimate object with a face.
  4. Explain to your "duck" what the problem is.
  5. As you're talking your "duck" will implant the answer into your brain! Eureka!

How does it work?

Rubber Duck Debugging works because it forces you to break down a complex problem into smaller chunks as you explain it to your duck. For example:

Dev: "Duck, why isn't my email sending?"
Duck: "..."
Dev: "The email is generated automatically when someone completes the contact form on my website, and it should then send to the site admin..."
Duck: "..."
Dev: "OMG DUCK I'M USING THE WRONG VARIABLE!"

Sometimes we developers can't see the forest for the trees. We're in so deep into our code that we can no longer see the problem, regardless of how obvious it may be. Breaking down the problem section by section, line by line, can help us realise where the issue is.

Speaking aloud also helps us hear our thoughts differently. The very act of hearing yourself explain the problem is often all you need to bring forth a solution. How often have you found yourself just asking "why?" in front of your code and BAM - the solution hits you.

Discussion: What's your experience with rubber duck debugging? Do you find it helps you? Also, please show me your ducks!

Top comments (11)

Collapse
 
david_j_eddy profile image
David J Eddy

I used jr. level team members. 'Hey, you want to help fix this?' I found it to be three-fold helpful:

1) I have to explain the issue and system using common understanding.
2) Helps the Jr. team member understand more concerning the system under work.
3) Shows that I do not know everything; as non of us do.

Together we would work through an issue and I would credit them with the solution in the Merge Request (public appreciation).

Anyone else every do this?

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚π₯𝐒𝐞 𝐝𝐞 π–πžπžπ«π

That's a great idea! I haven't tried it myself yet, but I will. I think number 3 is super important; it also teaches junior dev's that it's OKAY to not know everything and to ask questions.

Collapse
 
peledzohar profile image
Zohar Peled

public appreciation is also very important. Though my Jr. days are long forgotten, Nothing feels better than having a senior (at least, higher ranking than yourself) developer publicly credit you for your help.

Collapse
 
exadra37 profile image
Paulo Renato

Well when I was a freelancer I would just speak to my wife about my frustration with the problem, thus trying to explain it in non-technical words, was sometime just enough to shed some light in the right direction.

Now that I work in an office I just bug one of my colleagues... shame on me :(.

Another trick is to read your code backwards, because it breaks the way your brain is used to think about it.

Another way is to write the docs blocks for each class/function or the README, because it forces you to look into the problem from another perspective.

And for last, sometimes you just need to take a break, and suddenly, when you are not thinking on the problem anymore, your brain gets illuminate with a possible solution for it, or when you are back to the problem you are forced into a fresh start, its just like rebooting your Windows machine to get it back on the right track ;).

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚π₯𝐒𝐞 𝐝𝐞 π–πžπžπ«π

Must confess I do also speak to my colleagues sometimes - haha. I'm the only developer, so whilst some may understand technical terms, I do have to break things down as non-technically as possible. But you're right, doing this helps me solve the problem as I'm talking. To which I just jokingly thank them and turn back to my screen, leaving them a little dazed!

And for last, sometimes you just need to take a break, and suddenly, when you are not thinking on the problem anymore, your brain gets illuminate with a possible solution for it,

YES!! The amount of times I'm driving home and solve the problem I've been worrying over is incredible. I have to quickly grab my phone and record a possible solution so I don't forget it!

Collapse
 
exadra37 profile image
Paulo Renato

To which I just jokingly thank them and turn back to my screen, leaving them a little dazed!

I often say... Thanks for being my Rubber Duck ;)

And then they go.. What is that?

Then my fast answer is to show them this site.

YES!! The amount of times I'm driving home and solve the problem I've been worrying over is incredible.

Exactly, this our brain saying thanks for letting me to take a break ;)

But the hard part for me is giving up of trying to solve the problem and take the break or just work in something else ;)

Thread Thread
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚π₯𝐒𝐞 𝐝𝐞 π–πžπžπ«π

Haha I used to have a colleague whom I lovingly nicknamed Ducky, as he helped me solve soooo many problems!

Collapse
 
peledzohar profile image
Zohar Peled

That really depends on the problem, but yes - for anything that you can't find on the first search results page - attempting to explain your problem to anyone (or anything) that didn't read your code forces you to think differently. I also find that leaving your computer and try to use pen and paper to draw a crud flow-chart helps a lot.

I just got a rubber duck last week and it's sitting next to my computer at home.

This one looks just like him:
A lookalike for my rubber duck :-)

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚π₯𝐒𝐞 𝐝𝐞 π–πžπžπ«π

Duck-vader?! Love him! I want to buy an actual rubber duck (don't tell Stumps) but I worry I'll become hooked and need to buy ALL OF THE DUCKS. Haha.

But you're right, rubber ducking works best for logical problems, which can't be Googled.

Collapse
 
dechamp profile image
DeChamp

I totally agree with this! It's more about talking through it and giving your brain a chance to think about it. We can mindlessly thump away thinking we will find the solution just by keeping at it. I do find it very hard to talk to my rubber ducky in front of others, an insecurity issue. So I lean on my coworker for my rubber ducky when at work. They come over, I explain my issue... "nevermind, I realize the solution now". lol. But I think Stumps is awesome!

Collapse
 
nataliedeweerd profile image
𝐍𝐚𝐭𝐚π₯𝐒𝐞 𝐝𝐞 π–πžπžπ«π

I think my coworkers are now accustomed to be talking to myself, so they just ignore me for the most part now - haha! I do tend to whisper though, rather than speaking in a normal voice.