When a program doesn’t work as expected it has what is called a “bug” and it will be due to one of three reasons:
In 1946, a Harvard technical team was asked to take a look at a malfunction that was happening with the Mark II calculator. When investigating the issue and looking at Panel F they found something unsual between points in Relay 70. Operators traced the error in the Mark II to a moth trapped in the relay. The bug was removed and taped to the log book. Grace Hopper, an American computer scientist and United States Navy rear admiral working on the Mark II calculator project at the time, added the caption “First actual case of bug being found,” and that’s the first time anyone used the word bug to describe a computer glitch. Naturally, the term debugging followed.
Logic errors are often difficult to solve, especially if they are intermittent and only happen in particular circumstances. Talking through each program statement explaining what it does to another person can often result in an “ah-ha” moment and the discovery of a bug.
The rubber duck debugging technique, also known as “rubberducking” was popularised in the book, “The Pragmatic Programmer”, written by Andrew Hunt and David Thomas. A story describes how a programmer carried around a rubber duck and explained their code to it line by line when they encountered a bug. Talking to an inanimate object about the bugs in your code might sound silly, but it’s very popular among programmers because it works. In the rubber duck debugging technique, you don’t just explain the codes to the rubber duck line by line, you also tell the duck what exactly you’re trying to do and your goals for the code. When you explain everything about the code to the rubber duck, you’re much more likely to spot the bug hiding there.
It is becoming popular to provide students with a small rubber duck so that when their program doesn’t work, they can talk it through with the duck. Not only is this proven to be a useful debugging technique, but it also adds some humour into what is otherwise a very frustrating situation for students who need to accept that bugs and being stuck are a natural part of the programming process.