Rubber duck debugging

Last updated

A rubber duck in use by a developer to aid debugging Rubber duck assisting with debugging.jpg
A rubber duck in use by a developer to aid debugging

Rubber duck debugging (or rubberducking) is a debugging technique in software engineering. A programmer explains their code, step by step, in natural language - either aloud or in writing - to reveal mistakes and misunderstandings.

Contents

The name is a reference to a story in the book The Pragmatic Programmer . It tells a story of a developer who carried a rubber duck who explained their code to it line by line. [1] Variations of the practice use other objects or even pets; teddy bears are especially common. [2] [3]

Approach

Programmers often discover solutions while explaining a problem to someone else, even to people with no programming knowledge. Describing the code, and comparing to what it actually does, exposes inconsistencies. [4] Explaining a subject also forces the programmer to look at it from new perspectives and can provide a deeper understanding. [5]

The programmer explaining their solution to an inanimate object (such as a rubber duck) does not have to interrupt others. It also works better than thinking aloud without an audience. [6] This approach has been taught in computer science and software engineering courses. [7] [8]

On 1 April 2018, Stack Exchange launched an April Fools' Day joke called Quack Overflow. A rubber duck avatar appeared in the bottom right corner of the screen, listened to user problems, and pretended to type solutions, only to respond with a simple "quack" sound. It referenced rubber ducking as a powerful method for solving problems. [9]

See also

References

  1. Hunt, Andrew; Thomas, David (1999). The Pragmatic Programmer: From Journeyman to Master . Addison Wesley. ISBN   978-0201616224. p. 95, footnote.
  2. Debugging, Rubber Duck. "Rubber Duck Debugging". rubberduckdebugging.com. Archived from the original on 12 November 2020. Retrieved 14 September 2023.
  3. Boswell, Dustin; Foucher, Trevor (2011). The Art of Readable Code: Simple and Practical Techiques for Writing Better Code. O'Reilly and Associates. p. 137. ISBN   978-0596802295.
  4. Baker, SJ, The Contribution of the Cardboard Cutout Dog to Software Reliability and Maintainability, archived from the original on 5 October 2013, retrieved 9 February 2011.
  5. Hayes, David (25 June 2014). "The Psychology Underlying the Power of Rubber Duck Debugging". Press Up via Internet Archive. Archived from the original on 9 July 2014. Retrieved 10 September 2021.
  6. Byrd, Nick; Joseph, Brianna; Gongora, Gabriela; Sirota, Miroslav (2023). "Tell Us What You Really Think: A Think Aloud Protocol Analysis of the Verbal Cognitive Reflection Test". Journal of Intelligence. 11 (4): 76. doi: 10.3390/jintelligence11040076 . PMC   10146599 . PMID   37103261.
  7. Attwood, Jeff (2012). "Rubber Duck Problem Solving". codinghorror.com. Archived from the original on 12 February 2022. Retrieved 16 November 2021.
  8. Malan, David (2020). "Rubber Duck Debugging in CS50 IDE". noticeable.news.
  9. "Stack Exchange has been taken over by a rubber duck!". Meta Stack Exchange. 31 March 2018. Retrieved 1 April 2018.