Rubber duck debugging with Stackoverflow

In today’s post, I want to share a trick I discovered: using Stackoverflow to help answer my questions. Before you stop reading, I mean without posting my question at all. In fact, I simply rediscovered the time-honoured tradition of “rubber ducking”. I think Stackoverflow provides the perfect place to rubber duck and I’d like to share my reasoning.

Since I joined the community in 2009, I’ve asked my fair share of questions. In fact, as I write this, my question tally stands at 134. Of these, 99 have been answered by someone other than me. I can’t emphasise enough how helpful the Stackoverflow community has been to me during my career.

What you won’t see on my profile, however, are all the questions I spend time writing without ever pressing “submit”. I estimate that for every question I post, another four get discarded. That’s right: 80% of the questions I start composing in that big, inviting Stackoverflow “Ask a question” box never get seen by anyone but me. Why? Because 80% of the time I answer my own question during the process of formulating it.

I noticed that a while back that I was solving many of my problems (say, 50%) during the process of writing them up as Stackoverflow questions. A first this was annoying: if only I’d thought harder about the problem first, I wouldn’t have wasted all this time preparing a question! Later, it occurred to me that the process of explaining my problem to make it answerable by others was also making it answerable by me. In short, I was using Stackoverflow as a rubber duck.

Rubber duck debugging

Image courtesy of Tom Morris

“Rubber ducking” gets it name from a story recounted in The Pragmatic Programmer. This story features a programmer who found it useful to explain their problems to a rubber duck placed on their desk. It turns out that the act of vocalising the problem and describing it out loud (even if only to a rubber duck) is a really useful way to rethink it, and potentially arrive at an answer.

The magic here is that the act of explanation forces us to go back to basics and think about the problem holistically. To explain effectively, we find ourselves starting at the beginning and proceeding logically through each step, delving into details as we go. This helps to identify and isolate the nexus of a problem – what exactly is going on?

Once we’ve properly articulated the issue, the answer is often not too far away. Or, as the inventor Charles Kettering put it:

A problem well stated is a problem half-solved.

The difficult part of problem-solving is working out what needs solving. Rubber ducking is a surprisingly effective way of doing this.

Using Stackoverflow

So rubber ducking is a helpful approach to problem-solving. But why bother with Stackoverflow? Why not just use an actual rubber duck? Or a colleague? For me, it comes down to context. When I’m writing a question in that big box, I’m imagining what people will ask in the comments and try to pre-empt any missing details. As I’m forming the question, I’ll produce a “minimal, complete, and verifiable” example, I’ll go back and systematically check settings, and I’ll re-run everything one last time.

To reiterate my point from earlier, making a question answerable by the Stackoverflow community requires that it is well stated. I’m not alone in holding this view either. The official “How do I ask a good question?” guide on Stackoverflow itself has many suggestions, but my favourite is “Pretend you’re talking to a busy colleague”. You wouldn’t waste their time with a poorly thought-out question, so nor should you do the online equivalent. The venerable Jon Skeet suggests something similar in his blog post on writing the perfect question:

Once you’ve finished writing your question, read it through. Imagine you were coming to it fresh, with no context other than what’s on the screen. Does it make sense? Is it clear what’s being asked? Is it easy to read and understand? Are there any obvious areas you’d need to ask about before providing an answer?

By investing the time in making your question answerable by your peers on Stackoverflow, you’ll make it easier for you to answer the question yourself.

There’s another benefit too: as you’re rubber ducking with Stackoverflow, you’ll gain practice in writing answerable questions. It’s a difficult skill to master and there’s really no substitute for experience. As your questions improve, you may find, like I did, that you start to actually post questions less and less.

Finally, a bonus: if you don’t solve your problem during the writing process, you can still post your question (which by now will be highly answerable).

If you have any tips for rubber ducking with Stackoverflow, let me know in the comments.

6 Comments

  1. This is a good description of a common process… I assume that most questions I formulate must already have some answer or “almost answer” that I’ll be able to get to from following someone else’s train of thought. This is to the extent that I’ve been on stack overflow for years but I’ve never actually posted a question – which might be extreme, but I somehow arrive at the answer!

    Is it truly useful to post questions, or is most of the worth from gathering ideas from answers? [I guess that’s the point of your blog post…]

    Reply
  2. Thanks Christopher. I think there are probably a lot of people like you – getting value from Stackoverflow with actually needing to ever post questions. That said, I’ve had some really valuable interactions stemming from the questions I *have* posted, so don’t be too hesitant to jump in!

    Reply
  3. 김민준 I absolutely agree. In fact, 19 of my questions were self-answered (https://data.stackexchange.com/stackoverflow/query/729630/self-answered-questions-by-score?UserId=50151).

    I suppose that I tend to weigh up whether or not the answered question would likely prove useful for anybody else. Often-times, I realise that I’ve just made a silly mistake. In these situations, although I find the process of forming a question helpful, I’m not sure they would be of particularly high quality.

    Reply
  4. Good article. This is why I only ever asked one question on SO until today, because I always came up with some solution while trying to write a good question.

    On the other hand: why not taking this one step further and posting the question on SO anyway? Maybe somebody else comes up with an answer that is better than the solution one comes up with while trying to explain the problem, because they have some deeper insight into the topic? Also – a friend pointed out that it is perfectly o.k. to post the question if it hasn’t been asked yet and answer it yourself, after a while …

    Reply

Leave a Reply