PLIRO / Teaching material
Find bugs in code, one change at a time
A program can run and still draw something you did not intend. Start with a working square, deliberately change one turn and investigate how to repair it.
Start the working example01
What you will practise
- Compare an intended result with what the program actually does.
- Suggest a cause before changing anything.
- Test one change and explain why it helps.
02
What you need
- An internet-connected device with an up-to-date browser.
- Paper to record ‘expected’, ‘observed’ and ‘changed’.
- Optionally, the Dutch Bug Detectives worksheet.
Preparation
- Check that the starting program below draws a closed square.
- Try changing right 90 to right 100 yourself.
- The code below works; learners add the deliberate bug themselves.
Teaching material
Step by step
Keep a starting point
Open and run the program. You see a closed square. You can download the working source using the link under the example.
Add a deliberate bug
Choose Code, then Text. Change only right 90 to right 100. Leave everything else alone. Predict whether the shape will still close, then run it.
Describe the difference
The program turns 100 degrees four times: 400 degrees altogether, instead of a full turn of 360 degrees. The lines do not form a closed square.
Test one repair
Change the turn back to 90 and run again. Check the picture even when no error message appears. Running successfully is not the same as doing what you intended.
Make a test for a classmate
Ask a classmate to predict what forward 30 does instead of forward 60. It makes a smaller square and is not automatically a bug: your intention determines whether the result is right.
Try it yourself
This starting code works. Open the project, choose Code, then Text, to change something, then press Run.
# language: en
for side in [1, 2, 3, 4]:
forward 60
right 90
say "The shape is closed."
The example result
The working starting code and repaired version both draw a closed square. The version using right 100 shows why testing the result matters.
Discuss what you discovered
Explain ‘I intended …, I saw …, my test was …’. Allow different approaches that achieve the same result.
Extra material for this lesson
A next step
