CS 127: Data Structures, Fall 2001
C++ Programming Style

Section 1.3 of your textbook has a really good overview of programming style, which you should certainly consult. Here are some specific points that I think are particularly important:

1. Line up braces. You'll find that the textbook tends to use method (a), whereas I tend to use method (b). Either method is equally acceptable -- pick one and stick with it.
 
 
Method (a) Method (b)
if (a == b)
{
    c = d;
    e = f;
}
if (a == b) {
    c = d;
    e = f;
}

2. Use whitespace in a meaningful way to make your code readable:

3. Use capitalization to make your identifiers clear:


4. Keep your methods and functions short. A method shouldn't be longer than 1-2 screens without good reasons.

5. All classes should be defined in a header file (.h), and implemented in a code file (.cpp).

6. Each header file should contain header documentation containing:

7. Each class header should contain documentation containing 8. Each method and function should contain header documentation containing