4.1.1.10 Subroutines (procedures/functions) and 4.1.1.11 Parameters of subroutines Flashcards
What is a function?
A subroutine that’s called as part of an expression in a program, which returns a single value.
What is a procedure?
A subroutine called and executed which does not have to return a value
What is a parameter?
An item of data given to a procedure/function which is then given a value inside the subroutine and is used as a variable.
What’s the benefits of using subroutines / modular programming?
You can write a subroutine at a time which you can then easily test. Other people can understand the program more clearly and they can write more subroutines into your program without breaking it. You can reuse modules from other programs and replace them without affecting the whole program.
Code can be used ‘repeatedly’ within the same program ;
To make program debugging/testing/maintenance easier
What are the differences between a function and procedure?
A function returns a value, a procedure doesn’t have to.
A function appears in an expression but a procedure forms a statement of it’s own.
What is the importance of libraries?
A library is a collection of precompiled routines in a programming language. They are tried and tested so should reduce debugging and save time.
What is a subroutine
A sequence of instructions that can be called at any point after declaration in the program, making it an ‘out of line’ section of code
Procedures and functions are often self-contained. What is meant by the term self-contained in this context?
Do not use any global variables// use only local variables and/or parameters;
Give one reason why the use of global variables may introduce program bugs .
Local and global variables with the same name can be misidentified//difficult to test individual procedures/ functions//
Not clear that as a side-effect of executing procedure/function a global variable could change its value;