Subprograms, procedures and functions

In this session we will develop a software pattern for functions where we do not distinguish between leaf and non-leaf functions. We want to support the general case where a function can call other functions and can be called by other functions. For example, function funcA in the program illustrated by this flow chart:

Make sure to understand that this program could not be realized with the function call convention from Session 9.

Treating this more general case requires a new and different function call convention. Because of the curse of generality (i.e. “more general solutions are more complex”) we will approach this by seeking the special case in the general case. Therefore we categorize functions as follows and deal with the categories in that order:

  • Subprograms are functions that do not receive arguments and do not return a value,

  • procedures are functions that can receive arguments but do not return a value and

  • functions are the most general case, i.e. they can receive arguments and return a value.

Note that for the terms subprogram, procedure and functions a variety of definitions exist. We use and define them such that subprograms are a special case of a procedure and procedure are a special case of a function. That's because we want to start with a simple calling convention that can be generalized step by step.