1
Debug step by step
Computing 2: Unit 10, pp. 134–148
GoalUse clear steps to find and fix a bug in a program.
New words
bug · a mistake in a programdebug · to find and fix bugsfix · to change something so that it is right
Explanation
Debugging has steps. Run the program and watch it. Compare what happens with the algorithm. Find the block that is different. Fix that block. Then run the program again. Fix one bug at a time, so that you know what each change does.
Worked examples
The algorithm for the dog is: start on green flag, move right 2, say “Woof!”, stop. When we run the program, the dog says “Woof!” first and then moves. The order is wrong.
A child taps the character and nothing happens. The program starts on the green flag, but the algorithm says to start on tap. The first block is the bug.
| Bug | Fixed? |
|---|---|
| 1 the order is wrong | yes |
| 2 the number is wrong | not yet |
Class activity
Dance bugs: a grown-up writes a dance algorithm on paper: clap 2, stamp 3, turn around once, wave. One child performs the dance from cards that have two mistakes, for example clap 3 or the wrong order. The others follow the algorithm and shout “Bug!” when they see a difference. Then fix the cards and dance again.
Practice
1
The algorithm is: start on tap, move right 3, hop 2, stop. When we run the program, the character moves right 3 and hops 1. Which block has the bug and how do we fix it?
The hop block. Change 1 to 2.
2
Put the debug steps in order: A fix it, B run the program, C compare with the algorithm, D find the block that is different.
B, C, D, A. Then run the program again.
3
Why should we fix only one bug at a time?
Then we can see what each change does and we do not make new mistakes.
4
The algorithm is: start on green flag, move down 2, say “Hi!”, stop. How many bugs does this program have? What are they?
Two. It starts on tap but should start on the green flag, and it moves down 3 but should move down 2.