Rubber duck debugging

3 min read Original article ↗

From Wikipedia, the free encyclopedia

Code debugging method

A rubber duck in use by a developer to aid debugging

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

The name is a reference to an anecdote told in The Pragmatic Programmer by Andy Hunt and Dave Thomas. The book described rubber ducking as the method of explaining a problem to another party who do not "need to say a word; the simple act of explaining, step by step, what the code is supposed to do often causes the problem to leap off the screen and announce itself." The term referred to a research assistant Greg Pugh who carried around a rubber duck for this purpose. Variations of the practice use other objects or even pets; teddy bears are especially common.[1][2]

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.[3] Explaining a subject also forces the programmer to look at it from new perspectives and can provide a deeper understanding.[4]

The programmer explaining their solution to an inanimate object (such as a rubber duck) has the advantage of not requiring another human, but also works better than thinking aloud without an audience.[5] This approach has been taught in computer science and software engineering courses.[6][7]

On 1 April 2018, Stack Overflow 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.[8] It referenced rubber ducking as a powerful method for solving problems.[9]

  1. ^ Debugging, Rubber Duck. "Rubber Duck Debugging". rubberduckdebugging.com. Archived from the original on 12 November 2020. Retrieved 14 September 2023.
  2. ^ 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.
  3. ^ 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.
  4. ^ 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.
  5. ^ 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.
  6. ^ Attwood, Jeff (2012). "Rubber Duck Problem Solving". codinghorror.com. Archived from the original on 12 February 2022. Retrieved 16 November 2021.
  7. ^ Malan, David (2020). "Rubber Duck Debugging in CS50 IDE". noticeable.news.
  8. ^ Purushothaman, Praveen Kumar (31 March 2018). "Quack Overflow - Stack Overflow's take on April Fool!". Adventures (Blog). Retrieved 1 April 2018.
  9. ^ "Stack Exchange has been taken over by a rubber duck!". Meta Stack Exchange. 31 March 2018. Retrieved 1 April 2018.