|
|
|
|
|
|
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. |
|
|
|
|