< previous page page_a36 next page >

Page A36
until you reach an acceptable compromiseand then write an especially informative declaration comment next to the declaration.
Capitalization is another consideration when choosing an identifier. C++ is a case-sensitive language; that is, uppercase and lowercase letters are distinct. Different programmers use different conventions for capitalizing identifiers. In this text, we begin each variable name with a lowercase letter and capitalize the beginning of each successive English word. We begin each function name and data type name with a capital letter and, again, capitalize the beginning of each successive English word. For named constants, we capitalize the entire identifier, separating successive English words with underscore (_) characters. Keep in mind, however, that C++ reserved words such as main, if, and while are always lowercase letters, and the compiler will not recognize them if you capitalize them differently.
Formatting Lines and Expressions
C++ allows you to break a long statement in the middle and continue onto the next line. (However, you cannot split a line in the middle of an identifier, a literal constant, or a string.) When you must split a line, it's important to choose a breaking point that is logical and readable. Compare the readability of the following code fragments.
cout << For a radius of  << radius <<  the diameter of the cir
     << cle is  << diameter << endl;

cout << For a radius of  << radius
     <<  the diameter of the circle is  << diameter << endl;
When you must split an expression across multiple lines, try to end each line with an operator. Also, try to take advantage of any repeating patterns in the expression. For example,
meanOfMaxima = (Maximum(set1Value1, set1Value2, set1Value3) +
                Maximum(set2Value1, set2Value2, set2Value3) +
                Maximum(set3Value1, set3Value2, set3Value3)) / 3.0;
When writing expressions, also keep in mind that spaces improve readability. Usually you should include one space on either side of the = operator and most other operators. Occasionally, spaces are left out to emphasize the order in which operations are performed. Here are some examples:
if (x+y > y+z)
    maximum = x + y;
else
    maximum = y + z;

 
< previous page page_a36 next page >