Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 6 and Version 7 of code/C++_styleguide


Ignore:
Timestamp:
Oct 31, 2007, 10:24:50 AM (17 years ago)
Author:
patrick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/C++_styleguide

    v6 v7  
    182182
    183183
     184=== Constants ===
     185The use of magic numbers in the code should be avoided. Numbers other than 0 and 1 should be considered declared as named constants instead.
     186
     187
     188== Statements ==
     189
     190
     191=== Access Modifiers for Classes ===
     192The parts of a class must be sorted public, protected and private. All sections must be identified explicitly. Not applicable sections should be left out.
     193
     194
     195=== Type Casts ===
     196Type conversions must always be done explicitly. Never rely on implicit type conversion.
     197{{{
     198floatValue = static_cast<float>(intValue); // NOT: floatValue = intValue;
     199// or:
     200floatValue = float(intValue);
     201}}}
     202By this, the programmer indicates that he is aware of the different types involved and that the mix is intentional.
     203
     204
     205=== Encapsulation ===
     206Class variables should never be declared public. The concept of C++ information hiding and encapsulation is violated by public variables. Use private variables and access functions instead. One exception to this rule is when the class is essentially a data structure, with no behavior (equivalent to a C struct). In this case it is appropriate to make the class' instance variables public.
     207
     208
     209=== Loops ===
     210Only loop control statements must be included in the for() construction.
     211
     212
     213== Layout ==
     214=== Indentation ===
     215Basic indentation should be 2.
     216{{{
     217for (i = 0; i < numberOfElements; i++)
     218  a[i] = 0;
     219}}}
     220
     221
     222=== Block Layout ===
     223Block layout should be as illustrated in this example:
     224{{{
     225while (!done) {
     226  doSomething();
     227  done = moreToDo();
     228}
     229}}}
     230
     231=== Class Declaration ===
     232The class declarations should have the following form:
     233{{{
     234class SomeClass : public BaseClass
     235{
     236public:
     237  void functionBla();
     238
     239protected:
     240  ...
     241
     242private:
     243  ...
     244};
     245}}}
     246
     247
     248=== Function Definitions ===
     249Method definitions should have the following form:
     250{{{
     251void functionBla()
     252{
     253  ...
     254}
     255}}}
     256
     257=== If-Statement ===
     258The if-else class of statements should have the following form:
     259{{{
     260if (condition) {
     261  ...
     262}
     263else {
     264  ...
     265}
     266}}}
     267
    184268== Special Implementations ==
    185269=== Use STL Libraries ===