1
Write a little, test a little
Computing 2: Unit 10, pp. 134–148
GoalSay why we test a program after each small part.
New words
test · to run a program to see if it workspart · a small piece of a bigger programerror · a mistake
Explanation
A big program is easier to make in small parts. Write one part. Then test it before you write the next part. If you find an error, you know it is in the part you just wrote. Errors are easier to fix early. Then there are fewer errors at the end.
Worked examples
Ravi makes a story about a farmer. Part 1 is: start on green flag, say “Hello!”, move right 2, stop. He makes the blocks and taps the green flag. The farmer says “Hello!” and moves 2. Part 1 works.
Suppose Ravi typed 3 by mistake. When he tests part 1, the farmer moves 3 squares, not 2. He finds the wrong number at once, because he only wrote one part.
| When we test | Where is the error? |
|---|---|
| after each part | in the part we just wrote |
| only at the end | could be in any part |
Class activity
Build and check (pairs): one child writes an algorithm for part 1 of a short story, such as “start on tap, say Hello!, hop 2, stop”. The other child makes block cards for it on paper. Test by acting it out. Tick it, or fix it. Then write and test part 2. Did you find mistakes early?
Practice
1
Why is it better to test part 1 before you write part 2?
If there is an error, it is in part 1. There are fewer errors to find at the end.
2
Part 1 should say “Hi!” and then move up 2. Test the blocks. What is wrong?
The blocks are in the wrong order. The say block should come first.
3
Put these in the best order: A test it, B write one part, C fix any error.
B, then A, then C.
4
Nina wrote her whole program and tapped the green flag once, at the end. There were four errors. Why is this hard?
She cannot tell which block causes each problem, and the errors can mix together.