Computing
ComputingAlgorithms and programming30 min★★★ difficulty

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

designmodularprogramsproceduresfunctions

Scroll down — the lesson carries on below

Part 1 of 16 · Discover6%
1

Watch & discover

Part 1 of 16

Breaking a program into functions illustrationVisual introduction

Picture 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

2

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.

3

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.

4

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.

Stop here for now
5

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.

6

Quick check

Part 6 of 16

Quick check

What is decomposition?

7

Quick check

Part 7 of 16

Quick check

Why prefer parameters over global variables?

8

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.

Stop here for now
9

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.

10

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.

11

Quick check

Part 11 of 16

Quick check

Which three types of test data should you use?

12

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.

Stop here for now
13

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

14

Challenge round

Part 14 of 16

Game · Recall cards

A list stores…

Card 1 of 4

15

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. 1. A list stores…

  2. 2. A boundary test uses…

  3. 3. When debugging you should change…

  4. 4. What is decomposition?

16

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 Luna

Part 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

Good Learning Co. — personalised UK curriculum learning, built around what each learner loves.