SEN308 Lecture 6
SEN308 Lecture 6
SUBPROGRAMS
1. Efficiency
2. One-way or two-way
• These two are in conflict with one another!
• Good programming => limited access to variables, which means one-way
whenever possible
• Efficiency => pass by reference is fastest way to pass structures of significant
size
• Also, functions should not allow reference parameters
• C++ and Ada have overloaded subprograms built-in, and users can
write their own overloaded subprograms
• Design Issues:
1. Are side effects allowed?
2. What types of return values are allowed?
• Design Issues:
1. Are side effects allowed?
a. Two-way parameters (Ada does not allow)
b. Nonlocal reference (all allow)
2. What types of return values are allowed?
3. How many values can be returned?
• The nonlocal variables of a subprogram are those that are visible but not declared
in the subprogram
• Global variables are those that may be visible in all of the subprograms of a
program