The Rubber Duck method of debugging goes like this:
- Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck (bathtub variety).
- Place rubber duck on desk and inform it you are just going to go over some code with it, if that’s all right.
- Explain to the duck what you code is supposed to do, and then go into detail and explain things line by line.
- At some point you will tell the duck what you are doing next and then realise that that is not in fact what you are actually doing. The duck will sit there serenely, happy in the knowledge that it has helped you on your way.
This works amazingly well. There’s a whole section in the book The Pragmatic Programmer about it. Also, The Practice of Programming describes the close relative, the Teddy Bear method of Filtering Bug Reports:
One university computer center kept a teddy bear near the help desk. Students with mysterious bugs were required to explain them to the bear before they could speak to a human counsellor.
You should definitely get these books if you’re interested in reading about insights similar to the rubber duck. These books are full of great stuff, but especially The Pragmatic Programmer does an awesome job of explaining things such as the broken window theory, defensive programming, and the DRY principle.