< previous page page_358 next page >

Page 358
void Calc(  /* in */    int  alpha,
            /* inout */  & beta   )
// Precondition:
//    alpha and beta are assigned
// Postcondition
//    beta == beta@entry * 7 - alpha

{
    beta = beta * 7 - alpha;
}
This function first inspects the incoming value of beta so that it can evaluate the expression to the right of the equal sign. Then it stores a new value into beta by using the assignment operation. The data flow for beta is therefore considered a two-way flow of information. Pass-by-value is appropriate for alpha (it's incoming only), but pass-by-reference is required for beta (it's an incoming/outgoing parameter).
MATTERS OF STYLE
Formatting Function Headings
From here on, we follow a specific style when coding our function headings. Comments appear next to the formal parameters to explain how each parameter is used. Also, embedded comments indicate which of the three data flow categories each parameter belongs to (in, out, or inout).
void Print(  /* in */     float val,        // Value to be printed
             /* inout */ int& count )       // Number of lines printed
                                            //     so far
Notice that the first parameter is a value parameter. The second is a reference parameter, presumably because the function changes the value of the counter.
We use comments in the form of rows of asterisks (or dashes or some other character) before and after a function to make the function stand out from the surrounding code. Each function also has its own block of introductory comments, just like those at the start of a program, as well as its precondition and postcondition.
It's important to put as much care into documenting each function as you would into the documentation at the beginning of a program.

 
< previous page page_358 next page >