155

So I've read How to debug small programs, which is linked to from the Help Center and tells you how to debug your code.

It says "If your program still has a bug, obtain a rubber duck"; what does he mean by "rubber duck"? I'm not a native English speaker, so I don't know idioms like these; I translated and found it's actually a toy but relates to bathing.

So does he mean "bathe your code"? This doesn't make sense to me; could someone explain please?

25
  • 21
    hwrnmnbsol.livejournal.com/148664.html is the best explanation I've seen.
    – jscs
    Commented Dec 28, 2014 at 19:51
  • 170
    Well, it didn't mean me!
    – RubberDuck
    Commented Dec 28, 2014 at 21:53
  • 2
    Now maybe a link should be added from aforementioned help center topic to this question.
    – Ben Voigt
    Commented Dec 29, 2014 at 1:19
  • 2
    You can use a teddy bear, or a brick wall, or other inanimate object if you prefer. See Weinberg's Psychology of Programming for one of the earlier examples of its use. Commented Dec 29, 2014 at 9:00
  • 7
  • 8
    @RubberDuck: [citation needed]
    – PM 2Ring
    Commented Dec 30, 2014 at 7:24
  • 6
    This question appears to be off-topic because it belongs on a different stackexchange network such as programmers (and not on meta.stackoverflow)
    – Dexygen
    Commented Dec 30, 2014 at 16:34
  • 8
    @GeorgeJempty good point but hey you want me to ask on SO this: "what does rubber duck mean" well I don't think so.
    – niceman
    Commented Dec 30, 2014 at 16:36
  • 8
    @GeorgeJempty besides a question about something in the help center is a meta question I think
    – niceman
    Commented Dec 30, 2014 at 16:37
  • 2
    @progo sorry but anyway as I said, I've read it in the help center of SO.
    – niceman
    Commented Dec 30, 2014 at 16:59
  • 6
    @GeorgeJempty well when I first read it , you may laugh but I thought rubber duck is a name of a program that debugs your code
    – niceman
    Commented Dec 30, 2014 at 18:19
  • 4
    @GeorgeJempty at Programmers, it was asked and answered many times, eg here and here. Note first question is closed as a duplicate and second as opinion based - so please please Please stop using Programmers.SE as your toilet bowl
    – gnat
    Commented Dec 30, 2014 at 21:45
  • 7
    This belongs on MSO, not programmers, because programmers didn't link to the blog (if it did then it would belong on programmers meta). You link it, you get to explain it (which ChrisF did nicely).
    – psr
    Commented Dec 30, 2014 at 22:03
  • 4
    If this question didn't have the context of it being linked to by Stack Overflow, it would be off-topic for MSO. However, because it is linked by SO, this is a problem inherited by MSO.
    – Compass
    Commented Dec 30, 2014 at 22:11
  • 2
    "Rubber duck" is a term I've never heard in 45 years of programming. I would not expect someone to be familiar with the term unless they're in a culture where it's used regularly. It should not be used in any "external" written work unless some link to an explanation is provided.
    – Hot Licks
    Commented Dec 30, 2014 at 23:44

1 Answer 1

177

The phrase refers to the fact that the very act of explaining the problem to someone reveals the solution without them having to say anything. So you could have explained the problem to anyone or anything, including a rubber duck.

Wikipedia has a very short article on this which explains the origin of the phrase:

The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug his code by forcing himself to explain it, line-by-line, to the duck.

Note that the article you're reading goes on to explain this technique as well:

If your program still has a bug, obtain a rubber duck. Or if a rubber duck is unavailable, get another computer science undergraduate, it’s much the same. Explain to the duck using simple words why each line of each method in your program is obviously correct. At some point you will be unable to do so, either because you don’t understand the method you wrote, or because it’s wrong, or both. Concentrate your efforts on that method; that’s probably where the bug is. Seriously, rubber duck debugging works.[1. And as legendary programmer Raymond Chen points out in a comment to this entry, if you can’t explain to the duck why you’re executing a particular statement, maybe that’s because you started programming before you had a plan of attack.]

(Emphasis mine)

16
  • 7
    And you should really visit Raymond Chen's blog, he combines humor with great skill and experience.
    – rene
    Commented Dec 28, 2014 at 19:43
  • 5
    See also Ask the Duck
    – Robert Harvey Mod
    Commented Dec 28, 2014 at 22:10
  • 36
    There has been more than one occasion when I wandered into a co-worker's cubicle to explain a problem, then after I stated the issue, I discovered the issue, and said "Nevermind!" Commented Dec 28, 2014 at 23:56
  • 2
    In my experience, after a while, you don't need anymore this verbalization, then later you don't need any external entity (be it a duck or a co-worker) either, and you can simply solve the problems (the ones you can) by thinking about them. I guess it's some kind of internalization.... but for beginners the rubber duck is a real boon. Commented Dec 29, 2014 at 8:42
  • 4
    Pragmatic Programmer was late to the game. See Weinberg's Psychology of Computer Programming for an earlier example of the technique (c 1973 for the original edition; 1998 for the Silver Anniversary edition). Prag Prog was from 1999. Commented Dec 29, 2014 at 9:01
  • 17
    StackOverflow's Ask Question form is a great duck. Saves me from asking nearly half my questions. I don't even have to use my voice. Now if I can only somehow save the time it takes to type up half a question and just skip to the solution at the beginning...
    – Steven Lu
    Commented Dec 30, 2014 at 9:09
  • 6
    @StevenLu thats actually why it is good to teach asking understandable and complete questions on SO - it will help to solve the problems. Unfortunatellly a lot of people dont ask great questions and so they dont find the answers themselves it seems.
    – eckes
    Commented Dec 30, 2014 at 9:44
  • 11
    Anyone unfamiliar with this usage of "rubber duck" (even a native English speaker) would not be certain to realise that the usage is as a metaphor for "any inanimate object". This usage is an example of "I know it so I'm assuming everyone else does", which is a common usability problem. (My favourite example of this usability problem is at the Starbucks coffee shop where the staff assume you know their "name on cup" and "go over there to collect your purchases" procedures even though they never explain them.)
    – cja
    Commented Dec 30, 2014 at 10:07
  • I'd say that explaining your code reveals its problems, not its solution :p (And some kind of sanity check)
    – keyser
    Commented Dec 30, 2014 at 11:46
  • 2
    Ah, this is what I call "debugging by confessional".
    – Eric Lloyd
    Commented Dec 30, 2014 at 15:40
  • 1
    @StevenLu I just wish people would remember that the fact they are asking the question means there is something they don't know. All too often, instead of using SO as a rubber duck, they are using it as a screamfest to bash the stupid compiler which clearly must be chock full of bugs.
    – matt
    Commented Dec 30, 2014 at 15:59
  • This question belongs on programmers.stackexchange.com there are even duplicates over there e.g. programmers.stackexchange.com/q/194922 not on meta.stackoverflow
    – Dexygen
    Commented Dec 30, 2014 at 16:38
  • 5
    @GeorgeJempty - it's fine here as it's asking about something in the help.
    – ChrisF Mod
    Commented Dec 30, 2014 at 16:51
  • 3
    @ChrisF Maybe it doesn't belong in help then, seriously are we going to start asking questioners, "have you talked out loud about your problem"? The process of writing out the problem as a question is similar and should suffice. I've asked 100+ questions on SO, and at least a dozen times I've stopped myself before submitting because through formulating the question I've solved my problem.
    – Dexygen
    Commented Dec 30, 2014 at 16:55
  • @GeorgeJempty I was going to write the same.. I often start to write out a question on SO, only to realize halfway that either I was working on false assumptions or I know the answer... Then I usually erase it. Should I post it anyway? Commented Dec 31, 2014 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .