< previous page page_a35 next page >

Page A35
(Chapter 7 describes the purpose of labeling each parameter as /* in */, /* out */, or /* inout */.)
(3) Programmers sometimes place a comment after the right brace of a block (compound statement) to indicate which control structure the block belongs to:
while (num >= 0)
{
    .
    .
    .
    if (num == 25)
    {
        .
        .
        .
    } // if
} // while
Attaching comments in this fashion can help to clarify the code and to aid in debugging mismatched braces.
Identifiers
The most important consideration in choosing a name for a data item or function in a program is that the name convey as much information as possible about what the data item is or what the function does. The name should also be readable in the context in which it is used. For example, the following names convey the same information but one is more readable than the other:
datOfInvc     invoiceDate
Identifiers for types, constants, and variables should be nouns, whereas names of void functions (non-value-returning functions) should be imperative verbs or phrases containing imperative verbs. Because of the way that value-returning functions are invoked, their names should be nouns or occasionally adjectives. Here are some examples:
Variables
address, price, radius, monthNumber
Constants
PI, TAX_RATE, STRING_LENGTH, ARRAY_SIZE
Data types
NameType, CarMakes, RoomLists, Hours
Void functions
GetData, ClearTable, PrintBarChart
Value-returning functions
CubeRoot, Greatest, Color, AreaOf, IsEmpty

Although an identifier may be a series of words, very long identifiers can become quite tedious and can make the program difficult to read. The best approach to designing an identifier is to try writing out different names

 
< previous page page_a35 next page >