That Blue Square Thing

AQA Computer Science GCSE

May 2019: this area of the site is being built just now. I’m making progress but there are areas where there is no content yet. That will get added over the next 6 months or so.

Programming Concepts - Subroutines

Subroutines are an example of decomposition - a way of breaking a program down into smaller steps.

This is a key way to write better programs which are easier to write and test - and so are more likely to work better. It's also much easier to reuse sections of code from other programs if you're using well designed subroutines.

PDF iconSubroutines - basic ideas

There are advantages and disadvantages of using subroutines to decompose a program (although in general they are considered a "good thing" they do make some things a little trickier to achieve in a program using lots of variables).

PDF iconAdvantages and Disadvantages of using Decomposition - this is the same set of bullet points using on the algorithms page

Local and Global Variables

Variables are named areas of computer memory where data items can be stored.

Subroutines use variables. Sometimes those variables are declared (created) inside the subroutine - e.g. a variable to store the answer to one part of a calculation. There are called local variables.

Local variables cause some problems for programmers. In particular, they cannot be used anywhere other than in the subroutine. If you try and use it somewhere else, say in the main program, this will cause an error. They have a "local scope" - they are limited to the subroutine.

Global variables, on the other hand, are declared in the main program and can be used anywhere in the program - including inside subroutines. They have a "global scope".

PDF iconLocal and Global variables