r/AskProgramming • u/LowercaseSpoon • Dec 13 '20
Other Rubber duck debugging?
Stumbled upon an article that read when coders get stuck they tend to fall back on a rubber duck to debug. Is this actually true? How many people here actually practice this method?
69
u/A_Philosophical_Cat Dec 13 '20
I don't use a literal rubber duck, but it's definitely a thing where the act of explaining the problem to someone, even someone with no useful feedback to give, can help you come up with a solution.
Typically, I use a friend or coworker, but talking to a rubber duck would be equally effective.
28
u/hadidotj Dec 13 '20
My big "break through" moments are in the shower after dreaming about it all night........
26
u/flubba86 Dec 13 '20
After 5 years as a senior developer, last year I finally recognized the patterns I go though when stuck on a problem, and how to take advantage of it.
First, I allocate a slab of extra personal time to the problem, ie. I'll stay up late one night after dinner and work from 8pm till 1am. At around 1am I find my mind simply cannot crunch on it anymore and my brain starts to spin in circles (I recognize this when I keep forgetting which browser tab I'm supposed to be reading, or I forget which file I'm currently editing). Then I go to bed and sleep on it. The more sleep the better. It helps if I can sleep in until past 8am the next morning.
I will usually dream about the problem because its still in my head when I go to sleep. When I wake up, I jump in the shower, and while in the shower I will think about who can I draft an email to about this problem? eg. if its an open source library or tool I'm using, I'll think about who the maintainers are, or if its an internal project I'll think about which of my colleagues have experience with what I'm dealing with.
Then after breakfast I will sit down at my computer and draft an email to that person, (but leave the to: field blank, so I don't accidentally send it). I will write down my problem in excruciating detail. Including what I'm doing, why I'm doing it, everything I've done up to this point, what I'm attempting to do now, sample code snippets, what I expect the result to be, what I think my problem is, and how I think I might be able to solve it.
Usually during drafting that email I will need to double check some things. I don't want to look like an idiot with what I'm saying, or missing something obvious. So I double check my facts, double check my code, re-read some documentation, re-run my code, copy&paste some error messages. This is a critical process to go through, that I call sanity checking (and especially needed after a late night of going insane).
So by this point, 99% of the time I will have solved my own problem. At some point during writing the email and sanity checking myself I will have either stumbled across the problem and fixed it, or more likely I'll have discovered some fundamental logical flaw in what I'm doing and why I'm doing it that way, then change my approach to better fit the problem.
This pattern of events has happened so many times now, I've come to rely on it as part of my workflow. I think it could be considered a form of Rubber Duck debugging.
2
u/bstiffler582 Dec 13 '20
Not necessarily in the shower for me, but almost always AFK. E.g. while eating, walking or driving.
7
u/Biotot Dec 13 '20
Plenty of times I've told my coworker that I'm just going to talk at him trying to figure out a problem and he can ignore me.
Usually I talk myself into a solution. But occasionally he chimes in with some feedback or clarifying questions that help guide me to a solution.
I do have a personal plastic boba fett 'rubber dick' from 10 years ago that I mentally talk through some problems with but that's probably my last resort when I'm hard stuck.
2
u/KernowRoger Dec 13 '20
Yep I just talk programming at my wife and it often clicks. The other thing that works really well for me is getting some space from the project to let your brain think it over. Shower thoughts are real haha
1
u/the_bananalord Dec 13 '20
Typically, I use a friend or coworker, but talking to a rubber duck would be equally effective.
I'll be sure to let your friends and co-workers know
1
20
u/Ulsoro Dec 13 '20
This is actually a thing. https://en.wikipedia.org/wiki/Rubber_duck_debugging
Haven't seen too many actual rubber ducks, but the process of explaining your code, even to an inanimate object, forces you to think of and organize it differently than just reading. This difference can be almost like a second set of eyes, letting you catch things you've otherwise missed.
16
u/KingofGamesYami Dec 13 '20
Yes, it's true. I do it quite frequently, though I usually start writing an email or forum post instead of literally explaining to a duck. Usually solve the problem before I get to a message that is sufficiently detailed to send, and if I don't - well, I already did 90% of plan B.
3
Dec 13 '20
You also benefit from the added social pressure to explain it properly. I feel like sometimes I think "well, that works like this" while working through a problem and the part where I realize that doesn't make sense doesn't come until I'm saying it to a real person.
9
u/fzammetti Dec 13 '20
The more realistic rubber duck debugging is writing a Stack Overflow post. The solution usually materializes right before hitting the submit button (assuming your post was good and you actually tried a bunch of stuff and explained it all).
1
1
u/scienceNotAuthority Dec 13 '20
Same.
Although I one time explained my program to my wife, one line at a time and found I was running Home.js instead of Welcome.js
Not sure I would've figured it out typing up a question.
2
Dec 13 '20
Explain what rubber duck debugging is...
1
u/LordBrackets Dec 13 '20
Using an inanimate object, generally a rubber duck, to vent/explain your code and problems to. It is shown that explaining your problem to someone or something helps you work through it.
1
2
u/Fidodo Dec 13 '20
I think the reason it works is because you're breaking down the problem into small explainable pieces and that forces you to analyze the problem in much more detail, and in the process of doing that you pick up on steps or details you may not have been thinking about otherwise.
2
u/portol Dec 13 '20
yeap. very. this is why talking to one's self is considered normal for coders but for others can be considered a sign of madness.
2
u/JeamBim Dec 13 '20
The amount of times I have been writing a slack message to someone, or a thread on stack overflow and then figure it out in the process of explaining it and don't need to send it would astound you.
2
u/wrosecrans Dec 13 '20
One common variation is trying to write a good question on Reddit or Stack Overflow, so you start making a minimum example that demonstrates your problem, and organizing your thoughts about the problem so you can explain it succinctly in the Stack Overflow post... And by the time you are ready to ask for help, you no longer need it because you isolated the problem and clarified your understanding of it enough to solve it.
1
Dec 13 '20
This really is just a way of framing the common fact that when you go get another developer to check out "this thing that's happening that makes no sense" and you go to show them and it doesn't behave the same way, maybe because you went back a further step than when you were looking at it by yourself, that if you had have explained it without them there, then you still would have solved it.
1
1
u/rcls0053 Dec 13 '20
I have always found that talking to co-workers and bouncing off ideas has more than once resulted in better solutions. Now that Im working remotely I have an actual rubber duck (Doom Slayer) to whom I often talk to as my fiance doesnt care to listen. Talking to yourself and deconstructing your code helps. The rubber duck is just a replacement for an actual (very introverted) colleague, in my opinion.
1
Dec 13 '20
I had a Pop figurine of Corvo on my desk I would explain my issues to, the benefit of a “rubber duck” is you know they have no practical knowledge, so you immerse yourself into showing them everything from beginning to end.
Since WFH, I explain my development related issues to my cat and dog and walk them through it and hope I figure it out. Or I start an email to my boss and by the time I’m done detailing my issue I’ve probably solved my problem.
1
u/DarkNemesis200 Dec 13 '20
I always keep a couple of rubber duckies on my desk. Most powerful programming tool
1
Dec 13 '20
As most people here I use other people to explain them my problem before noticing myself what the solution should be. That said I do have a rubber duck next to me when working.
1
1
u/IllustriousFox4980 Dec 13 '20
I usually say to a coworker that I’m going to talk and they don’t need to listen to me and sometimes I don’t even need to start talking to have a brainwave. Probably think I’m a madwoman... ‘Hey can I chat though something with you actually thanks’
1
u/gale_wolf Dec 13 '20
Yes it's true. My colleague has a yellow rubber duck on his desk. He uses it and occasionally I've borrowed it for some rubber duck debugging of my own :)
1
u/Ran4 Dec 13 '20
I do that occasionally, though I usually talk to my self. So I guess I'm the duck.
But it does seem to work.
1
1
Dec 13 '20
I started with the rubber duck as a joke. But now it's kinda part of the character of my desk. It's my quiet friend that doesn't judge my code because it's dumb.
1
u/rybohii Dec 13 '20
Here's a video from a harvard professors lecture.
Look at the giant inflatable thing behind him.
1
1
0
Dec 13 '20
[deleted]
1
u/YMK1234 Dec 13 '20
just fyi, seems memegenerator triggers the reddit spam filter. would recommend imgur instead.
5
u/KingSSM Dec 13 '20
I'm a student so can't say much for the professional workplace but in an early on into class our teacher gave us rubber ducks. All his classes we can take them into the tests.