GCSE · Computer Science · OCR · Spec J277
Maintainability: sub programs
Imagine typing the same chunk of code every time you need it, then finding a mistake in it. In six places. Better plan: write it once, name it, call it.
Computer Science · Subprograms
One named task, called twice
Press Next to step through. The highlighted line is the one running, and the panel shows the values in play at that step.
Computer Science · Subprograms
Find the interface
Pick a part of the code, then choose which part of the interface it is.
Still to sort
Identifier (0)
The name the subprogram is known by.
Where the line is: It names the subprogram. It isn't a value going in or coming out.
Parameter (0)
A name in the brackets of the definition, ready to take a value in.
Where the line is: Parameters carry data IN. If it's what comes back, it's the return value instead.
Return value (0)
What the subprogram sends back out, written after return.
Where the line is: It carries data OUT of the subprogram, not in.
Two subprograms. (1) function discount(price, percent) … newPrice = price - price * percent / 100 … return newPrice … endfunction, called as sale = discount(40, 25). (2) function greet(name) … message = "Hi " + name … return message … endfunction.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Small named chunks of code, each doing one job, that make a big program easier to read, fix, test and share.
What you need to know
- A subprogram is a sequence of instructions that performs one specific task, and it has a name to identify it.
- Structured programming means dividing a program into smaller sections, called subprograms, each designed to do one specific task clearly.
- To run a subprogram, call it by name. Control jumps in, the task runs, and control comes back.
- Any subprogram can be called multiple times, so its code is written once instead of being repeated.
Have a goA program needs the same delivery-charge calculation in six different places. Written as a subprogram, how many times is that calculation's code written out?
Once. It is then called six times.
Each place calls the subprogram instead of having its own copy, so the code is written once. Six copies is exactly the repeated code a subprogram saves.
- Reading gets easier, because small chunks of code are much easier to read than one very large program.
- Maintenance gets easier: a change can be made and tested in one place without affecting the rest of the program.
- Testing gets easier too. A single task is simpler to test, and less code makes mistakes easier to find and fix.
- On a large program, several programmers can develop different subprograms at the same time, which speeds up development.
Have a goFour friends are building a big game together. One says: "Only one of us can touch the code at a time, so we'll just take turns." What could they do instead?
Split the game into subprograms and each develop different ones at the same time.
Several programmers can work on separate subprograms at once, which speeds up development. Taking turns on one huge block throws that advantage away.
- The interface decides how data passes in and out. It's made up of the identifier, the parameters and the return value.
- That 'rest of the program isn't affected' promise holds while the interface stays the same.
Have a goA subprogram called shipping is called from ten places. A programmer renames it postage. Does the rest of the program carry on untouched?
No. All ten calls still use shipping, so each one must change to postage.
The identifier is part of the interface, and every call uses it. Only changes that keep the interface the same leave the rest of the program alone.
The big picture
A subprogram is a sequence of instructions that performs one specific task and has an identifiable name. Structured programming divides a program into these smaller sections, each doing one job clearly. That makes code easier to read, easier to maintain and easier to test; one subprogram can be called many times instead of repeating code; and several programmers can develop different subprograms at the same time. Data passes in and out through the interface: the identifier, the parameters and the return value. A change can be made and tested in one place, as long as that interface stays the same.
Key points
Worked example
Problem
A quiz program works out a percentage score in three places, each with its own copy of the calculation: maths = 18 / 20 * 100, then science = 30 / 40 * 100, then history = 12 / 15 * 100. Rewrite it so the calculation is a subprogram, and check what each call returns.
⚠ Watch out
Saying a change to a subprogram can never affect the rest of the program. The change stays in one place only while the identifier, parameters and return value stay the same. Change one of those and every call must change too.
Memory hook
Name it, call it, reuse it. Data goes in through the parameters and out through the return value: that's the interface.
Check yourself
Name the three parts of a subprogram's interface, then give two reasons subprograms help programmers. (Identifier, parameters, return value. Any two: easier to read, maintain or test; less repeated code; several programmers at once.)
Flashcards
(11)What is a subprogram?
What is structured programming?
Why does splitting a program into subprograms make it easier to read?
How do subprograms make a program easier to maintain?
Why is a subprogram easier to test than a large block of code?
Why are mistakes easier to find and fix in a subprogram?
How does calling a subprogram save repeated code?
How do subprograms speed up the development of a large program?
What does a subprogram's interface determine?
What three things make up a subprogram's interface?
Which part of the interface carries data into a subprogram, and which carries data out?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.