Jeff Avery


Rubber Ducking

avatar

Yes I have a rubber duck on my desk.

I was reminded of this technique this morning while watching a great AI talk by Scott Hanselman. He and I are close to the same age, and we grew up learning to code in much the same way.

Rubber ducking (aka rubber duck debugging) is a technique for debugging coding problems. When you’re frustrated and can’t figure out what to do, you find someone who is willing to listen, and then you explain your code to them up to the point where the error occurs. 90% of the time, you will find the error yourself in the process of explaining it.

My wife is a lovely, patient woman - and my goto when I’m stuck. (“Honey, this fr*^&n Compose Library is buggy! You don’t believe what it’s doing! Come here and see this!”). When she’s not available, I turn to my duck instead. It works almost as well as presenting your problem to a person (although people do tend to ask better questions).

I think this technique works for much the same reason that talking about a topic cements your understanding of it; your brain is forced to slow down and think about the problem carefully, articulating each step. This forces you to identify and state your assumptions up-front - and those are often where your problem lies in the first place.

This is also one of the motivations behind pair programming. Want to be a better coder? Talk through it!