< previous page page_424 next page >

Page 424
Further Discussion: This problem is actually too simple to require such an involved structure. For example, some of the functions have only two lines of code in the body. We could just as easily have written these statements directly in place of the call to those functions. However, the problem does illustrate such concepts as interface design, pass-by-value, and pass-by-reference.
We don't mean to imply that you should never write a function with as few as two statements. In some cases, decomposition of a problem makes a two-line function quite appropriate. When deciding whether to code a module directly in the next higher level or as a function, ask yourself the following question: Which way will make the overall program easier to read, understand, and modify later? With experience, you will develop your own set of guidelines for making this decision. For example, if a two-line module is to be called from several places in the program, you should code it as a function. Look also at the Software Engineering Tip box for further guidelines.
SOFTWARE ENGINEERING TIP
Control Abstraction, Functional Cohesion, and Communication Complexity
The Transpose program contains two different While loops. The control structure for this program has the potential to be fairly complex. Yet if you look at the individual modules, the most complicated control structure is a While loop without any If or While statements nested within it.
The complexity of a program is hidden by reducing each of the major control structures to an abstract action performed by a function call. In the Transpose program, for example, reading and printing a person's last name is an abstract action that appears as a call to PrintName. The logical properties of the action are separated from its implementation (a While loop). This aspect of a design is called control abstraction.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Control Abstraction The separation of the logical properties of an action from its implementation.

 
< previous page page_424 next page >