Interesting way to double check your code.
Does the object have to be inanimate? I bet adopting this could be an additional argument for bringing dogs to work--I wouldn't mind explaining my code to my colleague's pug.
Oh, I had heard it was a code monkey! :D
Personally, I just talk to myself. :P
I've felt a bit crazy in the past when I've done this sort of thing. Though it does have its advantages.
I think this is where pair programming can help. I'd feel less silly if I was explaining the problem to another developer who also may be able to help.
I think the name is a bit of a misnomer. I think Rubber Duck Review would be a better name.
To me debugging means trying to track down a specific issue, which this is not an efficient means to do that. As I tell people the most important thing to do is to gather data and verify assumptions.
When you explain code you are still relying on your assumptions of the way that the code works. I can explain that this code does X. When I debug I want to verify did this code do X (possibly using logging or examining variables in a debugger).
Seems the outcome of this process is to make your code easier to read rather than locating and fixing defects.
That's a great point Dale. I would agree that this sounds more like a review process. It probably would be most beneficial to do at the psuedo-code or initial design phase. I tend to do this with comments and psuedo-code for hard problems now. But I don't talk through it out loud.
I always consider comments as the last resort. For really hard, unobvious code you should use comment. I prefer adding well named variables and methods that are named such that a comment is not necessary.
For example, if you have a few lines of code you need to explain, it is usually better to extract those lines of code into a method where the name of the method says what the code does (i.e. what you would have written in the comment).
What I am referring to is Introduce explaining variable and Extract Method refactorings first and then if absolutely necessary add comments.
A once-weekly round-up of the best programming and design posts.
Join 2050+ subscribers
We will never spam or share your email address. Easily unsubscribe