1
Find the bug
Computing 2: Unit 6, pp. 80–91
GoalSay what a bug is and find it by comparing a program with its algorithm.
New words
bug · a mistake in an algorithm or a programdebug · to find a bug and fix itcompare · to look at two things to see how they are the same or different
Explanation
A bug is a mistake in an algorithm or a program. To debug means to find the bug and fix it. We find a bug by comparing the program with the algorithm, one step at a time. Look for a wrong block, a wrong number, a missing block or blocks in the wrong order. Fix one bug, then run the program again.
| Kind of bug | Algorithm says | Program has |
|---|---|---|
| wrong block | hop 2 | grow 2 |
| wrong number | right 4 | right 5 |
| missing block | say “Hi!” | (nothing) |
| wrong order | up 1, then left 2 | left 2, then up 1 |
Worked examples
The algorithm says: start on tap, say “Go!”, right 3, pop, end. Compare each block. Steps 2 and 3 are in the wrong order. The character moves before it speaks.
The algorithm says: right 4, then up 2, to reach the star. The program says right 4, then up 3. The cat goes one square too far.
The algorithm says: start on tap, say “Hi!”, hop 2, end. The program has no say block. The say block is missing.
Class activity
Bug hunt (with a partner): one of you writes an algorithm with five steps on paper, for example “start on flag, right 2, hop 1, say Go!, end”. Then draw five block cards for a program, but make one mistake on purpose. Hide the mistake. Your partner puts the cards next to the algorithm and checks them one by one with a finger. Can they find the bug? Swap roles.
Practice
1
The algorithm says: start on green flag, left 2, grow 1, play pop, end. Find the bug in the program.
Step 3. The program has shrink, but the algorithm says grow.
2
What does it mean to debug a program?
To find a mistake in the program and fix it.
3
The cat should go right 3 and then down 2 to the fish. The program says right 3, up 2. The line shows where the cat went. Which block is the bug and what must it be?
The up 2 block. It must be down 2.
4
Name two kinds of bug.
Any two, for example a wrong block, a wrong number, a missing block or blocks in the wrong order.