Breaking a program into functions
One long program is hard to fix. Six small functions are six small problems.
Part of your national curriculum
- Algorithms and programming: Design and develop modular programs that use procedures or functions, and test and correct them systematically
Lesson overview
What you'll learn in this lesson
Design and develop modular programs that use procedures or functions, and test and correct them systematically
Key learning points
- • Decomposition
- • Parameters and return values
- • Systematic testing
This lesson at a glance
- 30 minutes
- 16 parts to scroll through
- 3 quick checks
- Marked quiz at the end
- Gentle pace: short sittings with pauses
Words to know
Scroll down — the lesson carries on below
Watch & discover
Part 1 of 16
Visual introductionPicture this
Breaking a program into functions
One long program is hard to fix. Six small functions are six small problems.
In a nutshell
Design and develop modular programs that use procedures or functions, and test and correct them systematically
Learning cycle
Part 2 of 16
Learning cycle 1 of 2
Part 1 · Decomposition
A short piece of teaching, then a check to make sure it has landed.
Explore the idea
Part 3 of 16
Learn
Decomposition
Split the job into tasks that each do one thing: get input, validate it, calculate, display. Each becomes a function with a clear name.
Reset break
Part 4 of 16
Pause
That's sitting 1 of 4 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Explore the idea
Part 5 of 16
Learn
Parameters and return values
Pass data in through parameters and hand the result back with a return, rather than relying on global variables. That makes each function testable on its own.
Quick check
Part 6 of 16
Quick check
Part 7 of 16
Reset break
Part 8 of 16
Pause
That's sitting 2 of 4 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Learning cycle
Part 9 of 16
Learning cycle 2 of 2
Part 2 · Systematic testing
A short piece of teaching, then a check to make sure it has landed.
Explore the idea
Part 10 of 16
Learn
Systematic testing
Test each function with normal, boundary and erroneous data. Fixing a bug inside one small function cannot break the rest of the program in the way an edit to a long script can.
Quick check
Part 11 of 16
Reset break
Part 12 of 16
Pause
That's sitting 3 of 4 done
Stretch, get a drink, look out of the window. There is no timer and nothing is counting down — your place is saved, so you can come back in five minutes or tomorrow.
Challenge round
Part 13 of 16
Game · Sort it
Which of these are true?
Drag each card into the right column. Tap a card first if dragging is fiddly.
True
Not true
Challenge round
Part 14 of 16
Game · Recall cards
A list stores…
Card 1 of 4
Mastery quiz
Part 15 of 16
Marked quiz
End of lesson quiz: Breaking a program into functions
4 questions, marked with the reasoning shown. No timer.
1. A list stores…
2. A boundary test uses…
3. When debugging you should change…
4. What is decomposition?
Lesson round-up
Part 16 of 16
Lesson round-up
Ready when you are
Quiz score
Not sat
Games
Not played
Points this lesson
0
Best run
0 in a row
Luna: 0 out of 3 on the practice checks. Only if you feel up to it — one more?
Ask LunaPart 1 of 16 · Watch & discover
How this is going
- Not looked at yet
Design and develop modular programs that use procedures or functions, and test and correct them systematically
