< previous page page_434 next page >

Page 434
Next Steps
With templates and exceptions under your belt, you are well equipped with some of the more advanced aspects of C++. Before you put the book down, however, let's take a moment to discuss some points about writing professional-quality code. When you go beyond hobbyist interest and work as part of a development team, you must write code that not only works, but that can be understood by others. Your code also must be maintained and supported, both by you, as the customer's demands change, and also by others after you leave the project.
Style
Although it doesn't matter which style you adopt, it is important to adopt a consistent coding style. A consistent style makes it easier to guess what you meant by a particular part of the code, and you avoid having to look up whether or not you spelled the function with an initial cap the last time you invoked it.
The following guidelines are arbitrary; they are based on the guidelines used in projects I've worked on in the past, and they've worked well. You can just as easily make up your own, but these will get you started.
As Emerson said, Foolish consistency is the hobgoblin of small minds, but having some consistency in your code is a good thing. Make up your own, but then treat it as if it were dispensed by the programming gods.
Braces
How to align braces can be the most controversial topic between C and C++ programmers. Here are the tips I suggest:
Matching braces should be aligned vertically.
The outermost set of braces in a definition or declaration should be at the left margin. Statements within should be indented. All other sets of braces should be in line with their leading statement.
No code should appear on the same line as a brace. For example:
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
if (condition==true)
{
   j = k;
   SomeFunction();
}
m++;

 
< previous page page_434 next page >

If you like this book, buy it!