Class 6 · Unit 5: Computational thinking · Lesson 5.5 · 40 min
Bug hunters
1947: a computer gives wrong answers. Inside, engineers find a moth. Every mistake since has been called a bug — and finding them is a skill.
Today you will: Hunt bugs in three broken programs · Use predict, run, spot, change one thing · Catch a bug hiding at the edge
Story
In 1947, engineers working on an early computer at Harvard University found that it was giving wrong answers. When they looked inside, they found a moth stuck in one of the parts! They taped it into their notebook with the words "first actual case of bug being found".
People had used the word "bug" for machine faults even before that. But since then, every mistake in a program has been called a bug, and fixing it is called debugging.
Every programmer, including the people who build AI, spends a large part of their time debugging. Making mistakes is normal. Finding them is a skill.
Watch
How to hunt a bug — scan code 6.5.5 in the printed book.
Warm up your fingers
Practise accuracy over speed. Today, careful eyes matter more than fast fingers.
- typing.com: any lesson you have already passed, aiming for 95% accuracy or more
- Notice: when you make a typing mistake, you debug it with Backspace.
On the laptop
You need: Scratch Desktop (offline, no account) · a bug log in your notebook or in Calc: Bug · What should happen · What happened · What I changed · Fixed?
Build each program exactly as written — bugs and all. Then predict, run, spot and fix.
Mission 1: Bug 1 — the square that isn't (pairs, 5 min)
Supposed to: draw a square.
when green flag clicked erase all pen down repeat (3) move (100) turn ↻ (90) degrees- ☐1
Predict: what shape will it draw? Then run it. (How many sides does a square have?)
- ☐2
Change one thing and test again. Fill one row of your bug log.
Mission 2: Bug 2 — the cat that never stops (pairs, 5 min)
Supposed to: say "Salaam!" once when clicked.
when this sprite clicked forever say [Salaam!] for (1) seconds wait (1) seconds- ☐3
Run it. Which block keeps going and never ends? Fix it, and log it.
Mission 3: Bug 3 — the apple sorter that sorts wrong (pairs, 8 min)
Supposed to: say "Good apple" if the size is more than 6, otherwise "Small apple".
when green flag clicked set [size] to (8) if <(size) < (6)> then say [Good apple] else say [Small apple]- ☐4
Size is 8. What does it say? What should it say? Fix it.
- ☐5
Test it properly: size 3, size 8, and size 6. What happens at exactly 6 — is that what we want? That's an edge case.
Finished early?
Make your own program with one hidden bug. Swap with a partner and hunt each other's bug.
No laptop today?
The teacher writes the three programs on the board. In pairs, act each one out step by step, find the mistake, write the fix, and fill in the bug log in your notebook.
Now you know
- A bug is a mistake in a program. Debugging is finding and fixing it.
- Four steps: predict → run → spot → change one thing.
- One change at a time so you know what fixed it.
- Test different values including tricky ones at the edge, like exactly 6.
- AI has bugs too. Models are tested with new examples and improved again and again.
Debate it
A program that sorts apples for a fruit trader has a bug. For a week, it puts good apples in the "small" box, and the farmer is paid less. Who should fix it, and who should make things right for the farmer? Why is testing a program before people rely on it an act of amanah (trust)?
Check yourself — practice, not a test
1. What is debugging?
- ○ Writing a program for the first time
- ○ Finding and fixing mistakes in a program
- ○ Deleting a program
- ○ Making a program run faster
2. Put the bug hunt steps in order:
- 1. Spot the difference
- 2. Run the program
- 3. Predict what should happen
- 4. Change one thing and test again
3. A square is drawn with repeat (3) [move 100, turn 90]. What is wrong?
- ○ The move should be 90
- ○ It should repeat 4 times, not 3
- ○ The turn should be 100
- ○ Nothing is wrong
4. It is best to change many things at once when debugging, to save time.
- ○ True
- ○ False
5. A tricky test value right at the border of a condition, like exactly 6, is called an ______ case.
Remember
Everyone makes bugs. Good programmers find them: predict, run, spot, change one thing.