Lesson 4: Splitting a big job into parts
Unit overview - Previous: Lesson 3 - Next: Lesson 5
About 45 minutes.
Goal
Children split a bigger program into smaller parts, each write one part,
join the parts and test them with a list of events. They test one part at a
time to find which part has a bug.
Materials
- Per group of four: two boxes labelled "red" and "blue", and two sets
of number cards 0 to 20 (both boxes can hold the same number, such as 0,
at the same time).
- Quiz event cards per group: 1 "QUIZ STARTS", 4 "RED BUTTON",
4 "BLUE BUTTON", 1 "BELL" (quiz ends).
- Blank index cards for the parts, and paper and pencils for the traces.
- The job description (below) on the board.
- A class trace table on the board (columns: event, step, red, blue).
Steps
Opening (5 min)
- Say: "The Little Hill library is having a pretend quiz with a red team
and a blue team. Each team has a button. The library wants a program
that keeps both scores."
- Put up the job description:
- At the start, both scores are 0.
- When the red button is pressed, red gets 1 more.
- When the blue button is pressed, blue gets 1 more.
- At the end (the bell), both scores are said.
- Say: "That is a big job. Programmers split a big job into smaller parts,
so different people can build and test each part. This is called
decomposing the problem."
Main activity (30 min)
Part 1: name the parts (5 min). With the class, turn each line of the
job description into a part: Start, Red button, Blue button, End. Each
child in a group of four takes one part.
Part 2: write the parts (8 min). Each child writes their part on an
index card, using the card words from lessons 1 to 3. One correct set:
Part 1 (Start)
WHEN QUIZ STARTS:
SET red TO 0
SET blue TO 0
Part 2 (Red button)
WHEN RED BUTTON:
CHANGE red BY 1
Part 3 (Blue button)
WHEN BLUE BUTTON:
CHANGE blue BY 1
Part 4 (End)
WHEN BELL:
SAY red
SAY blue
Other wordings that do the same job count.
Part 3: test each part, then join (9 min). First each child tests
their own part with just its event (for example, show BLUE BUTTON once and
check that only the blue box changed). Then the group lays the four cards
side by side and runs the test list:
QUIZ STARTS, RED BUTTON, BLUE BUTTON, RED BUTTON, RED BUTTON, BELL.
| Event |
Step |
red |
blue |
| QUIZ STARTS |
SET red TO 0, SET blue TO 0 |
0 |
0 |
| RED BUTTON |
CHANGE red BY 1 |
1 |
0 |
| BLUE BUTTON |
CHANGE blue BY 1 |
1 |
1 |
| RED BUTTON |
CHANGE red BY 1 |
2 |
1 |
| RED BUTTON |
CHANGE red BY 1 |
3 |
1 |
| BELL |
SAY red, SAY blue |
3 |
1 |
(Says red 3, blue 1.)
Part 4: a bug in one part (8 min). Show this version of Part 3:
Part 3 (Blue button)
WHEN BLUE BUTTON:
CHANGE red BY 1
Run the same test list. (Red 4, blue 0, instead of red 3, blue 1.) Ask:
"Which part would you test first?" (The blue button part, because the blue
score never changed.) Show BLUE BUTTON alone: the red box changes, so the
bug is in Part 3. Fix it to CHANGE blue BY 1 and run the list again.
(Red 3, blue 1.)
Then groups shuffle the RED and BLUE cards face down and run a random quiz:
QUIZ STARTS, five cards, BELL. The check is that the trace matches the
cards.
Discussion questions (with answers) (5 min)
- "Why split the program into parts?" (Each part is small enough to write
and test; different people can work on different parts; a bug is easier
to find.)
- "How did testing one part at a time help?" (It showed which part was
wrong, so only that part needed fixing.)
- "Why does this program need two variables?" (It has to remember two
different scores at the same time.)
Closing check (with answers) (5 min)
- "QUIZ STARTS, BLUE BUTTON, BLUE BUTTON, RED BUTTON, BELL. What is
said?" (Red 1, blue 2.)
- "Part 1 is missing. From an earlier quiz, the boxes hold red 3 and
blue 1. Then RED BUTTON, BELL. What is said, and what should it be?"
(Red 4, blue 1; it should be red 1, blue 0.)
- "Name the four parts of the quiz program." (Start, Red button, Blue
button, End.)
Vocabulary
decompose, part, test, join, two variables
Differentiation
- Support: The child writes the Red button part with the Blue button
part as a model next to it. Pair a child with a partner for the trace.
- Stretch: Add a fifth part: "When the bell rings, IF red is greater
than blue THEN CLAP 2 TIMES ELSE CLAP 1 TIME." Test it with a list where
the scores are equal. (Equal scores give one clap, because red is not
greater than blue.)
- Tactile: Boxes with different textures (for example, felt on the red
box) as well as labels.
Safety
Teacher notes and misconceptions
- Some children think each part needs its own copy of the start steps.
Show that one Start part sets both scores.
- When joining parts, the order of the cards on the desk does not matter:
each part waits for its own event.
- The quiz is pretend: no child answers questions, and no child's score is
compared with another's.