A2.1 Finding and fixing bugs
A bug is a mistake in code that makes the program do the wrong thing. Testing runs the code and compares what happened with what you wanted. Debugging finds the line that caused the difference. Refining makes the fixed program shorter or clearer.
Example
The robot was meant to reach the flag two squares ahead and one to the right, but ended one to the left. Test it.
- Test: trace the blocks on the grid — forward, forward, turn left, forward lands one to the LEFT.
Example
Find the bug and fix it.
- Debug: the third block is the bug; it turns the other way. Change turn left to turn right.
Remember: Refine: the two forwards could become repeat 2: forward.
A2.2 Coding in daily life
Example
Describe how code changes life for someone using a thermostat and a wheelchair ramp sensor.
- Thermostat: code turns the furnace on below a set temperature and off above it, so the house stays even without anyone watching.
- Ramp sensor: code detects a chair and opens the door, so a person enters without help.
Example
Describe how code changes life for someone using an online map.
- Map: code finds the shortest route, so a trip takes less time and fuel.
Summary
- Test: compare what happened with what you wanted.
- Debug: find the line; fix it.
- Refine: shorter and clearer.
- Code in machines saves effort, time and fuel.