< previous page page_437 next page >

Page 437
All other identifiers should use mixed caseno underscores. Function names, methods, class, typedef, and struct names should begin with a capitalized letter. Elements like data members or locals should begin with a lowercase letter.
Enumerated constants should begin with a few lowercase letters as an abbreviation for the enum. For example:
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
enum TextStyle
{
    tsPlain,
    tsBold,
    tsItalic,
    tsUnderscore,
};
Comments
Comments can make it much easier to understand a program. Often, you will not work on a program for several days or even months. In this time you can forget what certain code does or why it has been included. Problems in understanding code can also occur when someone else reads your code. Comments that are applied in a consistent, well-thought-out style can be well worth the effort. There are several tips to remember concerning comments:
Wherever possible, use C++ // comments rather than the /* */ style.
Higher-level comments are infinitely more important than process details. Add value; do not merely restate the code. For example:
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
n++; // n is incremented by one
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
This comment isn't worth the time it takes to type it in. Concentrate on the semantics of functions and blocks of code. Say what a function does. Indicate side effects, types of parameters, and return values. Describe all assumptions that are made (or not made), such as assumes n is non-negative or will return -1 if x is invalid. Within complex logic, use comments to indicate the conditions that exist at that point in the code.
Use complete English sentences with appropriate punctuation and capitalization. The extra typing is worth it. Don't be overly cryptic, and don't abbreviate. What seems exceedingly clear to you as you write code will be amazingly obtuse in a few months.
Use blank lines freely to help the reader understand what is going on. Separate statements into logical groups.

 
< previous page page_437 next page >

If you like this book, buy it!