Chances are, you’ve probably been rubber duck debugging without even knowing it. Here’s how:
You’re in the zone. The world fades. You type away and every line of code works as expected. Whoever said coding is hard to learn?
And then, boom! You get a bug—an error in your code.
Naturally, your first instinct is to ask Google, so you copy and paste your bug. First stop: Stack Overflow (a question-and-answer site where you can get solutions). You read through a few questions and solutions, trying to find one that works for you.
You try it out, but it doesn’t work. This cycle goes on and on for three hours. By now, you are absolutely lost. Your thoughts are completely entangled, and what’s worse: Every tweak you make to your code increases the bugs.
You check your phone. Your friend tried to reach you, so you call them back.
Before you realize it, you are telling them all about your code.
They ask you a few questions. All of a sudden, you thank them profusely and say you’ll call them back in an hour or so. Your friend is dumbfounded, but they agree anyway.
What you have done is known as “rubber duck debugging” or “rubber ducking”.
But what exactly is it? What does it have to do with ducks? Let’s explore this concept further.
If you’d like to skip ahead to a particular section, simply use the clickable menu:
- What is rubber duck debugging?
- Where did the term rubber duck debugging come from?
- Rubber ducking: A step-by-step guide
- Other useful programming techniques
- Code reviews
- Pair programming
- Extreme programming
- Final thoughts
1. What is rubber duck debugging?
Rubber duck debugging is a programming technique used to help with debugging—fixing errors in your code.It involves explaining your code and what you are trying to achieve to a rubber duck, in its literal sense.
If you want to learn about the wider area and other techniques, check out our beginner’s guide to debugging.
Why talk to a duck? I mean, a duck can’t engage you in conversation, or pinpoint a missing semicolon!
The whole point here is that you need to explain your code to something or someone.
The “duck” here could be anything or anyone. It could be a friend or colleague at work. If you’re a remote developer, it could be a flatmate or family member.
It could even be a pet—bunnies and stuffed frogs are acceptable, too.
Image source: Reddit
The recipient might help you with the thought process by asking questions or not.
As you explain your code, you become more aware of your thought process and where you are going wrong.
If your “duck” in this place is a human, then they might help by asking for clarifications or questions that point you in the right direction.
Note that your “human duck” doesn’t need to be a software engineer or web developer—any sympathetic ear will do!
Where did the term rubber duck debugging come from?
Rubber ducking, as a concept, was introduced as a story in The Pragmatic Programmer—a book written by Andrew Hunt and David Thomas in 1999.
In the story, a programmer would carry a rubber duck and explain code to it line by line.
2. Rubber duck debugging: A step-by-step guide
The first step in the rubber ducking process involves, of course, getting your rubber duck.
Next, explain what your goal is—what you are trying to achieve with your code.
For example, let’s say that you are trying to write code that can send a bill after 30 days. You, however, have no idea how to go about adding 30 days to the current start date.
Here are the rubber-ducking steps you would take:
- Tell your duck the goal that you want to achieve: send a bill after 30 days.
- Explain what you have done to achieve the goal. Talk about every line of code.
- Inform the duck about any errors you have encountered.
As you explain your errors, you’re most likely to see where you were going wrong, or the direction in which to take your research.
Yes, you will have hit your eureka moment.
Where your “duck” is another human, you’re highly likely to receive feedback.
The other person may question your thought process. Or why you chose to approach a problem the way you did.
An important tip is that you need to be able to receive feedback and respond without getting defensive.
3. Other useful programming techniques
In this section, we look at more programming approaches that you can add to your coding arsenal:
Code reviews
Code reviews are primarily focused on code quality.
In code reviews, you have your “peers” go through your code, identifying mistakes and better ways you might have written it.
Your peer might point to a variable name that is not obvious, for example.
Pair programming
In pair programming, two developers work together to implement features. There are two main roles—navigator and driver.
The navigator “advises” on what to do. They might say, for example, “create a function without parameters”. The driver then does what the navigator asks him to do.
The driver can question the navigator’s direction and ask for clarification. It’s a collaborative effort.
The roles of the driver and navigator switch from time to time.
The amazing thing about pair programming is that you also get to debug your code together. You kind of have an “ever-present duck”.
Pair programming is part of another technique known as extreme programming. Let’s learn about it next.
Extreme programming
Extreme programming, or XP in short, is not an extreme sport.
You don’t get to code while dipped in ice-cold water for 30 minutes or something.
XP is a programming method of building software quickly while adapting to customer requirements.
In extreme programming, the customer is the focus. And because customer needs can change from time to time, with XP, developers are able to implement them almost immediately.
Customer requirements can be implemented at any stage of the Software Development Life Cycle, or SDLC.
Yes, software development follows a cycle—a number of phases or stages that are followed before we say that software is ready to be “launched” into the market.
Developers will need to go above and beyond to match changing customer requirements. This is where the concept of “extreme programming” comes in.
How might you practice XP as a beginner?
One of the ways you can practice XP as a beginner is by having a mentor. The mentor can act as your “customer”.
They’ll review your code and what features you have built, and make suggestions.
XP with a mentor is not synonymous with rubber ducking. It does, however, keep you on your toes to keep the customer in mind. This way, you might reduce the bugs in the first place, as you’re focussing on the customer.
4. Final thoughts
You don’t have to get frustrated and smash your computer on the wall when you encounter a bug.
Now have a tool that you can use to smush any bugs and find your way when you are stuck—rubber duck debugging.
We weren’t joking earlier—you might as well buy yourself a literal rubber duck and put it on your desk. It’ll surely go a long way toward helping you understand your thought process.
Better still, if you have any web developer friends, a rubber duck would make a thoughtful gift.
When coupled with other techniques like code reviews, pair programming, and extreme programming, rubber ducking becomes even easier.
Why not start practicing the rubber duck method via CareerFoundry’s free 5-day coding short course? Even though it’s designed for absolute beginners, you’re sure to run into at least a small snag at some point—it happens to all of us!
In the short course, you’ll build a website from scratch using HTML, style it with CSS, and add functionality via JavaScript.
Take a sneak-peak at the first lesson in this video, where our in-house developer Abhi introduces you to the project:
Otherwise, if you’d like to read more about the world of coding, check out these articles:
- What’s the Easiest Programming Language to Learn?
- What Does a Software Engineer Do?
- Cloud Computing With AWS: A Beginner’s Guide
FAQs
What is the rubber duck debugging trick? ›
The idea behind the rubber duck debugging technique is that when a programmer gets held back by bugs, the code is explained line by line to a rubber duck. Think about this technique as a process in which you type a message to be posted on social media and read it out loud before you post it.
What is the the rubber duck method? ›The Rubber Duck Debugging theory is commonly used by programmers. The idea is that when a programmer needs to debug their code, they should explain the program line-by-line to a rubber duck. Often, the act of explaining the problem step by step will cause the solution to present itself.
Why is it called rubber duck debugging? ›The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line by line, to the duck.
What is rubber duck in coding? ›In IT, the slang term “rubber duck debugging” has been created to describe an often effective yet simple strategy for debugging code. In rubber duck debugging, the programmer sits a small rubber duck (or other inanimate object) near them on a desk or near a computer, and explains the code to the duck line by line.
How do you win a rubber duck race? ›The Rubber Duck Race is just that, a race between a large amount of rubber ducks. The raffle involves participants buying a numbered rubber duck to represent them in the race. The rubber ducks are then let out at the top of a river and the first to reach the finish line is the winner.
Why do people hide rubber ducks? ›Hiding rubber ducks on cruise ships is a fun way to connect with other passengers on your next sailing, as well as a fun pastime on sea days. Whether you find a duck and contact the folks who hid it or hide your own flock so others can reach out to you, it can help you to make new friends from all corners of the globe.
Who invented rubber ducking? ›The first, invented in 1931 by Eleanor Shannahan of Maryland USA, was designed as an aquatic toy that could sit either above or below the surface of the bath, and would emit jets of water from the mouth and other small holes.
Why do rubber ducks have a hole in the bottom? ›Tip to Keep Your Bath Toys from Molding
Some bath toys have a small hole in the bottom or are manufactured to take in water and squirt. They are cute toys, but they collect mold – quickly.
The yellow rubber duck has achieved an iconic status in Western pop culture and is often symbolically linked to bathing. Various novelty variations of the toy are produced, and many organisations use yellow rubber ducks in rubber duck races for fundraising worldwide.
Why is a rubber duck yellow? ›Real ducks are white, so why are rubber ducks yellow? What caused this? Well, if you think about it, rubber ducks are supposed to look like baby ducks, so it makes sense that they're yellow.
Why is it called duck typing? ›
The name comes from the phrase, “If it walks like a duck and it quacks like a duck, then it must be a duck.” Duck typing is related to dynamic typing, where the type of the class of an object is going to be less important than the methods that it defines.
Which programing language uses duck typing? ›What languages support duck typing? Python and Ruby support duck typing, both of which are dynamic typed languages. In general, dynamic typed languages such as JavaScript and TypeScript support duck typing.
Is duck ducky or rubber? ›The rubber ducky (also spelled duckie) has come a long way from his first concept as a chew toy for children. While the origin of the first rubber ducky is uncertain, many rubber molded toys came about when rubber manufacturing developed in the late 1800s.
What age are rubber ducks for? ›Product Dimensions | 4 x 3 x 3 inches |
---|---|
Item model number | 0L-1XWW-S202 |
Manufacturer recommended age | 3 years and up |
Best Sellers Rank | #72,504 in Toys & Games (See Top 100 in Toys & Games) #565 in Preschool Bath Toys #744 in Bathtub Toys |
Customer Reviews | 4.5 out of 5 stars 331Reviews |
The rubber ducks spanned 5,497 feet and it took over 30 minutes to walk the entire path. The public were able to adopt ducks, with funds supporting community organizations.
Why should I buy a rubber duck? ›Rubber Ducks are the epitome of childhood simplicity: they float, they squeak, they squirt and they promise hours of good clean fun for kids who otherwise would shun bath time. 5. Rubber Ducks reside in millions of hot tubs worldwide bringing fun, smiles and comfort-even a little nostalgia. 6.
Why do people leave rubber ducks on your car? ›Some found Jeep Ducking, when you find another Jeep in the wild, you leave a rubber duck somewhere on it for the owner to find. The goal is that they'll post a photo of it on social media, and then pass the duck along to keep the game going.
Can rubber ducks get moldy? ›Toys that have a hole in them can have a slimy blackish-green build-up inside! A 2018 study from Swiss researchers shows that soft plastic bath toys like rubber duckies are breeding grounds for mold, bacteria, and fungi — some of which can make kids sick.
What does BF mean on Princess Cruises? ›Category BF - Balcony Stateroom (Guarantee) Description: Balcony staterooms are impressive and offer the elegance of a balcony with fine patio furniture. They offer all the amenities of an interior stateroom, plus a spacious closet and desk. You are guaranteed an Balcony stateroom or better!
Who owns the most rubber ducks in the world? ›TODAY SHOW show on NBC spotlights Charlotte Lee, the Guinness World Record-holder for the largest collection of rubber ducks. She takes us inside her vast assortment of more than 9,000 duckies and tells us how she sourced them from all over the world, including hard to find duckies from Ducks in the Window.
Do adults use rubber ducks? ›
Adults, too, appreciate rubber ducks. Collectors proudly display variations of the classic form that proclaim their affinity to colleges, careers, sports, celebrities, and holidays. Aficionados adorn their homes with rubber duck–themed shower curtains, towels, bathrobes, nightlights, and wallpaper.
What does the rubber duck mean for jeeps? ›The reason doesn't matter, because ducking is meant to spread joy to other Jeep drivers and is a silly trend that has origins in Canada. The trend started in the summer of 2020 when the creator thought that more smiles were desperately needed.
What does the rubber duck do in house game? ›Chapter 1. As Tabby, the ducky essentially has no function apart from a small Easter egg. Tabby can pick it up and throw it across the room, causing it to make a squeaking sound. She can also pour a bucket of water on it, which turns it into a real duck, and awards an achievement.
What is a rubber ducky moment? ›Have you ever had a eureka moment while explaining something to someone? That's what rubber ducking seeks to replicate. Essentially, rubber ducking is about talking through your coding problems with a friendly duck that won't judge you.
How do forces make a rubber duck float on water? ›Some force pushes the rubber duck to the top of the water. That force is buoyant force, the upward force that fluids exert on all matter. Air is a fluid, so it exerts a buoyant force.
What is getting ducked for Jeep owners? ›Jeep ducking is a trend among the enthusiastic global community of Jeep owners, where they place rubber ducks on each other's vehicles for a heartwarming surprise.
Do all Jeeps get ducked or just Wranglers? ›All models of Jeeps are open to ducking. There are no “official rules.” However, people who drive the Wrangler model (known for years as the CJ model) are more likely to “duck” a fellow Wrangler. That's not to say that the “duck-er” needs to be actually driving their Jeep while doing the “duck-ing.”
Why do people put yellow ducks on Jeeps? ›Duck Duck Jeep started from the concept of ducking Jeeps, but with an added note to show some ducky love to other fellow Jeep owners. Davidson said that the Jeep ducking tradition is a way to bring smiles to people's faces and a fun way to make someone's day.
What does the flower do in Duck game? ›Simply place the flower near their corpse, and press fire when unarmed and roughly by the corpse's head. This would normally close the eyes of the departed duck, but if in proximity to a flower, they will turn into a lethally-heavy tombstone and funeral music will play.
What does the evil duck do? ›These evil ducks are used for unlocking the Doom Easter Egg, located at the lowest level of the VNC Tower. Be warned as it will take longer than just a couple of minutes to get your hands on all the black ducks, and even then your job isn't done.
What happened to the rubber ducks answers? ›
Carried by ocean currents, over 20 years later, they are still being washed ashore, on Hawaii, Alaska, South America, Australia and the Pacific Northwest. They are found frozen in Arctic ice, and washed up in Scotland and Newfoundland in the Atlantic.
How old is the rubber duck? ›Rubber toys first appeared in the late 1800s, when manufacturers made use of Charles Goodyear's process for rendering rubber into malleable material. The first rubber ducks didn't even float: they were cast solid and intended as chew toys.
What does a yellow duck symbolize? ›The yellow rubber duck has achieved an iconic status in Western pop culture and is often symbolically linked to bathing. Various novelty variations of the toy are produced, and many organisations use yellow rubber ducks in rubber duck races for fundraising worldwide.
How do you remove water from duck rubber? ›Dry. Fill the basin with hot soapy water (or use a squirt of shampoo), squeeze the air out and allow the cavity of the toy to take in fresh, hot soapy water. Do this a few times until the water runs clear. Squeeze out the water thoroughly and leave the toy to dry so any excess water can drain out.
How do rubber ducks squeak? ›Rubber ducks don't just quack! They squeak too! These colored rubber ducks come with a squeak hole at the bottom which allows them to float upright and make squeaking sounds.
Does eraser sink in water? ›The eraser still sinks! Sinking is a property of eraser rubber no matter how small it is and how little it weighs.