Structured programming and subroutines (procedures and functions) — AQA GCSE Computer Science
Structured programming decomposes complex problems into smaller, manageable subroutines such as functions and procedures to improve readability and code reuse. Master the core difference: functions always return a value to the calling routine, whereas procedures execute a sequence of statements without returning a value.
Structured programming and subroutines (procedures and functions) explained
A subroutine can declare several parameters, separated by commas, and a call must then supply the same number of arguments in the same order.
Read the full explanation
For example, a procedure to record a score might take a player name and a points value; the call passes a string and an integer in that order, and inside the subroutine each parameter holds its matching argument. Order matters: swapping arguments sends the wrong data to each parameter. Multi-parameter subroutines let one routine handle related data together, such as calculating an area from length and width, and returning or displaying a result. Learners should write definitions and matching calls, and trace which value each parameter receives.
Your focus
- Write a subroutine definition that declares more than one parameter.
- Write a call that supplies matching arguments in the correct order.
- Trace which value each parameter receives and the resulting output or return value.
Which command word is this?
Give the main characteristics of a programming technique, such as describing how parameter passing works without needing long justifications.
Structured programming and subroutines (procedures and functions) exam tips
Topic Overview
Structured programming is a software development approach that breaks a large, complex problem down into smaller, self-contained sub-units known as subroutines. In AQA GCSE Computer Science, this involves mastering top-down modular design, parameter passing, and distinguishing between procedures and functions.
Using subroutines improves code maintainability, reduces redundancy through reuse, and allows teams of developers to collaborate effectively on distinct program components. Understanding local and global variable scope ensures robust software that avoids unintended side effects during execution.
Key Concepts
- →Modular decomposition: Breaking down a complex program into smaller, independently testable subroutines.
- →Procedures vs. Functions: Functions compute and return a value to the calling environment, whereas procedures execute instructions without returning a value.
- →Parameters and Arguments: Parameters are the variable placeholders defined in the subroutine header; arguments are the actual values passed during a subroutine call.
- →Scope of Variables: Local variables exist only within the subroutine where they are declared, while global variables remain in memory throughout the entire execution.
Marking Points
- A subroutine definition can list more than one parameter, separated by commas, each with a name.
- A call must supply the same number of arguments as there are parameters.
- Arguments are matched to parameters by position, so order matters.
- Inside the subroutine each parameter holds its corresponding argument and can be used in expressions or output.
- A multi-parameter subroutine can combine related data, for example computing an area from length and width.
- Swapping the order of arguments passes the wrong data to each parameter and produces incorrect results.
- Tracing a call shows which value each parameter receives and what the subroutine outputs or returns.
Examiner Tips
- 💡Write the definition and a matching call so the parameter-to-argument mapping is visible.
- 💡State explicitly that arguments are matched by position and order matters.
- 💡Trace one call step by step, showing the value held by each parameter.
- 💡When asked to write an algorithm that calculates and provides a result, always declare it as a function and include an explicit 'return' statement.
- 💡Use distinct, descriptive names for parameters to show good programming practice; avoid using identical names for global variables and subroutine parameters.
Common Mistakes
- Supplying fewer or more arguments than parameters: correction is to match the count exactly.
- Reversing argument order so values land in the wrong parameters: correction is to keep the order defined in the parameter list.
- Treating parameters as shared global values: correction is to recognise each parameter is local to that subroutine call.
- Believing 'print' and 'return' are identical: Outputting text to the screen using a print command does not pass a value back to the program logic; only a return statement provides data to the caller.
- Assuming global variables are always preferable: Students think global variables make coding easier, but examiners penalise failing to recognise that global variables consume memory permanently and increase the risk of accidental overwriting across subroutines.
Revision Plan
- 1Step 1: Practice identifying the difference between procedures and functions in Python or AQA pseudo-code.
- 2Step 2: Write short subroutines that accept one or two parameters and return calculated outputs.
- 3Step 3: Trace programs containing both local and global variables using trace tables to observe how variable scope functions.
- 4Step 4: Complete past AQA Paper 1 algorithmic questions requiring subroutines and modular design.
Exam Question Types
- 📋Definition and comparison questions: Explaining the technical difference between a function and a procedure, or local and global variables (typically 2-4 marks).
- 📋Code analysis and trace tables: Following subroutine calls, tracking arguments passed through parameters, and determining output values.
- 📋Algorithm design tasks: Writing pseudocode or high-level code for a specific subroutine to solve a stated computational problem (typically 4-6 marks).
Command Word Expectations (AQA)
Give the main characteristics of a programming technique, such as describing how parameter passing works without needing long justifications.
Set out the causes, reasons, or mechanisms clearly. For example, explain why using local variables is better practice than global variables by giving a point and its consequence.
Construct valid pseudocode or high-level program code that satisfies all functional criteria stated in the scenario, using appropriate identifiers and constructs.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A program calculates the delivery charge for a package. If the weight is under 5 kg, the charge is £3.50. If the weight is 5 kg or more, the charge is £7.00. Write a subroutine using pseudocode or Python called 'calcDelivery' that takes 'weight' as a parameter and returns the correct delivery fee.
- 1.Step 1: Choose the correct subroutine type. The question specifies that the routine must return a value, so it must be declared as a function.
- 2.Step 2: Define the subroutine header with one parameter: 'calcDelivery(weight)'.
- 3.Step 3: Implement selection logic using an IF-ELSE structure comparing 'weight' against the threshold of 5.
- 4.Step 4: Use the return statement within each branch to output the numerical value (£3.50 or £7.00).
Question: Explain two advantages of using structured programming and subroutines when developing a large software system with a team of developers. [4 marks]
- 1.Step 1: Identify advantage 1 related to team workflow and modular development.
- 2.Step 2: Explain advantage 1: Breaking the project into subroutines allows tasks to be divided among different team members to work on independently.
- 3.Step 3: Identify advantage 2 related to maintenance, debugging, or reusability.
- 4.Step 4: Explain advantage 2: Subroutines can be tested, debugged, and reused independently without affecting the rest of the program.