Cover Design - Programming in C++, Rules and Recommendations
Sample Chapter From Programming in C++, Rules and Recommendations
Copyright © FN/Mats Henricson and Erik Nyquist
1 Introduction
The purpose of this document is to define one style of programming in C++. The rules and recommendations presented here are not final, but should serve as a basis for continued work with C++. This collection of rules should be seen as a dynamic document; suggestions for improvements are encouraged. A form for requesting new rules or changes to rules has been included as an appendix to this document. Suggestions can also be made via e-mail to one of the following addresses: erik.nyquist@eua.ericsson.semats.henricson@eua.ericsson.se
Programs that are developed according to these rules and recommendations should be:
- correct
- easy to maintain.
- have a consistent style,
- be easy to read and understand,
- be portable to other architectures,
- be free of common types of errors,
- be maintainable by different programmers.
In order to obtain insight into how to effectively deal with the most difficult aspects of C++, the examples of code which are provided should be carefully studied. C++ is a difficult language in which there may be a very fine line between a feature and a bug. This places a large responsibility upon the programmer. In the same way as for C, C++ allows a programmer to write compact and, in some sense, unreadable code.
Code written in bold type is meant to serve as a warning. The examples often include class definitions having the format "class {};". These are included so that the examples may be compiled; it is not recommended that class definitions be written in this way. In order to make the code more compact, the examples provided do not always follow the rules. In such cases, the rule which is broken is indicated.
Many different C++ implementations are in use today. Most are based on the C++ Language System by AT&T. The component of this product which translates C++ code to C is called Cfront. The different versions of Cfront (2.0, 2.1 & 3.0 are currently in use) are referred to in order to point out the differences between different implementations.
Rule 0 Every time a rule is broken, this must be clearly documented.
0 comments: