The C++ programming language is a free form language: it has no requirements about where program elements must be placed on the line or on the page. Consequently the programmer has complete freedom of program style. But experienced programmers know that the tasks of writing, debugging, and maintaining successful software are greatly facilitated by using a consistent, readable programming style. Moreover, others will find your programs easier to read if you conform to standard style conventions. Here are some simple rules that most C++ programmers follow:
- Put all your #include directives at the beginning of your file.
- Put each statement on a new line.
- Indent all statements within a block.
- Leave a space on either side of an operator, like this: n = 4
Another worthwhile convention to follow is to choose your variable names carefully. Use short names to minimize the chances for typographical errors. But also pick names that describe what the variable represents. This is called self-documenting code. Nearly all C++ programmers follow the convention of using exclusively lowercase letters in variable names, except when a name is composed of several words where the first letter of each appended word is capitalized. For example:
these names are easier to read than middleInitial and maxUnsigneInt. As an alternative, some programmers use a underscore to simulate blanks, like this:
Ref. By: JOHN R. HUBBARD, Ph.D. (Professor of Mathematics and Computer Science, University of Richmond)