Debug It! 🐛
What You'll Learn
- What a bug is and where the word comes from
- How to read a broken program and find the mistake
- How to fix bugs by testing and comparing results
What Is a Bug?
A bug is a mistake in a program that makes it do the wrong thing. Every programmer — from beginners to professionals — writes bugs. What separates good programmers is how well they find and fix them.
The process of finding and fixing bugs is called debugging.
In 1947, a computer at Harvard University stopped working. Engineers found a real moth stuck inside the machine causing the error. They taped it into their logbook and wrote "First actual case of bug being found." The word has meant a software error ever since!
How to Debug
When your program does not do what you expected, follow these steps:
- Observe — Run the buggy program. Watch carefully what the turtle actually does.
- Compare — Compare what you see to what you wanted. Where did it go wrong?
- Hypothesize — Make a guess about which block caused the mistake.
- Fix and test — Change that block and run it again. Did that fix it?
- Repeat — If it is still broken, repeat the process.
Go through each block one at a time in your head and picture what the turtle is doing at that exact moment. The bug is usually in the block where your mental picture diverges from what you wanted.
Three Buggy Programs to Fix
Below are three programs that are supposed to draw a square — but each one has a different bug. Load each one, run it to see what it draws, find the bug, and fix it.
Bug 1 — Wrong step count: The program uses 4 moves and 4 turns but the sides are unequal. Find which Move block has the wrong number and fix it.
Expected: Move Forward 80 → Turn Right 90° → repeated 4 times
Bug 2 — Wrong turn direction: The program moves and turns but the turtle spirals instead of making a square. One turn block is pointing the wrong way.
Bug 3 — Missing block: The program draws 3 sides of a square and stops. Something is missing at the end.
1. What is a bug in programming?
2. What is the first step in debugging a program?
3. The word "bug" in programming comes from…