U2b - Programming techniques Flashcards
Examples of subroutines
Functions, procedures
What’s the difference between a function and a procedure?
Procedures execute code in a subroutine but they don’t return anything. Functions will return a value after processing has taken place e.g. input returns what the user typed in, random returns a number
Define parameters
Values that you can pass through a subroutine
Advantages of subroutines (4)
- Each subroutine can be tested separately to make sure it works correctly
- Many programmers can work on a large program at the same time which cuts down development time
- Subroutines can be re-used in other programs
- Program maintenance is easier - if you make a mistake, then you only have to modify the subroutines affected
Difference between global and local variables
Global variables are outside of the subroutine, whereas local variables can only be seen and used inside the subroutine
What are global variables?
Variables that are accessible anywhere in the program. They’re written in pseudocode using the global keyword
What are local variables?
Variables that only exist while the subroutine is executing. They are only accessible within the subroutine.
Advantage of using local variables
They keep a subroutine self-contained, so they can be used in any program without variable names conflicting with those used in the calling program
Advantages of using structured programming techniques (2)
- The modularised approach of using subroutines breaks down programs into manageable chunks of code, and this helps to decompose larger problems
- By using structured programming techniques, programs will have fewer bugs and be easier to maintain
Define scope
The area of a program where an item is recognised
Define subroutine
A selection of code that can be grouped together under a name, and then called later in the program
Define data validation
Routines that ensure that data entered is of the right type
Define range check
Ensures that a number or date is within a sensible/allowed range
Define type check
Ensures that data is of the right type, such as integer, letter or text
Define length check
Ensures that text entered is not too long or too short e.g. a password between 8 and 15 characters