Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 4 and Version 5 of code/C++_styleguide


Ignore:
Timestamp:
Oct 30, 2007, 4:27:19 PM (17 years ago)
Author:
patrick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/C++_styleguide

    v4 v5  
    88Remember that any violation to the guide of course is allowed if it enhances readability.
    99
    10 == File Organization ==
     10== Files ==
    1111=== Header and Source ===
    1212Keep your classes/files short, don't exceed 2000 LOC (if it get's longer you may separate functions into different modules). Put every class in a separate file and name the file like the class name (don't use !CamelCase names separate them with underlines). Create a separate header (ends with .h) and source file (ends with .cc). Example for class {{{MyExampleClass}}}.
     
    2626Place machine-dependent code in a special file so that it may be easily located when porting code from one machine to another.
    2727
     28=== 80 Columns at Maximum ===
     29File content must be kept within 80 columns.
     30''Comment: 80 columns is a common dimension for editors, terminal emulators, printers and debuggers, and files that are shared between several people should keep within these constraints. It improves readability when unintentional line breaks are avoided when passing a file between programmers.''
     31
    2832== Comments ==
    2933
     
    3539
    3640== Naming Conventions ==
     41
    3742=== Classes and Types ===
    3843Names representing types must be in mixed case starting with upper case.
     
    4651
    4752=== Variables ===
    48 Variable names must be in mixed case starting with lower case.
     53Variable names must be in mixed case starting with lower case. Each variable declaration on a new line. Avoid abbreviations in names.
    4954{{{
    5055string testString;
     
    5863  int numberOfTimes_;
    5964};
    60 
     65}}}
     66Use useful names:
     67{{{
     68// wrong
     69ProgressBar *prbar;
     70string prtxt, errstr;
     71 
     72// correct
     73ProgressBar* downloadProgressBar;
     74string progressText;
     75string errorString;
     76}}}
     77''Comment: Apart from its name and its type, the scope of a variable is its most important feature. Indicating class scope by using underscore makes it easy to distinguish class variables from local scratch variables. This is important because class variables are considered to have higher significance than method variables, and should be treated with special care by the programmer.''
    6178
    6279=== Constants ==
    63 Named constants (including enumeration values) must be all uppercase using underscore to separate words. Always use constants instead of numbers.
     80Named constants (including enumeration values) must be all uppercase using underscore to separate words. Always use constants instead of numbers. 
    6481{{{
    6582const int MAX_ITERATIONS = 5;
     
    6986
    7087=== Functions ===
    71 Names representing methods or functions must be verbs and written in mixed case starting with lower case.
     88Names representing methods or functions must be verbs and written in mixed case starting with lower case. Avoid abbreviations in names.
    7289{{{
    7390void calculateTheLowerBoundary() {}
    7491int howManyItemsLeft() {}
    7592}}}
    76 For interface functions to local member variables use short functions:
     93For interface functions to local member variables use short functions (setter and getter functions):
    7794{{{
    7895class WorldEntity {
     
    91108}}}
    92109
     110The name of the object is implicit, and should be avoided in a method name.
     111{{{
     112class Line {
     113public:
     114  float getLength(); // Not getLineLength() since it's clear that it is a line.
     115};
     116}}}
    93117
     118=== Enumerations ===
     119Enumeration constants can be prefixed by a common type name.
     120{{{
     121enum Color {
     122  COLOR_RED,
     123  COLOR_GREEN,
     124  COLOR_BLUE
     125};
     126}}}
     127
     128=== Namespaces ===
     129Names representing namespaces should be all lowercase.
     130{{{
     131namespace ioutil {
     132
     133}
     134}}}
    94135
    95136== Indentation ==
    96137=== Spaces ===
    97138Use 2 spaces for an indentation level. Never use tabs, as it is common in windows IDEs.
     139
     140
     141== Whitespaces ==
     142Use one space after each keyword
     143
     144
     145
     146
     147
     148
    98149
    99150== Special Implementations ==