Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 24 and Version 25 of code/C++_styleguide


Ignore:
Timestamp:
Sep 21, 2008, 8:11:52 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/C++_styleguide

    v24 v25  
    88
    99Remember that any violation to the guide of course is allowed if it enhances readability.
     10
     11----
     12
     13== General ==
     14=== this ===
     15Address all member variables and functions with the this-> operator:
     16{{{
     17this->processData(this->data_);
     18}}}
     19
     20=== const ===
     21Use const when it's possible. This includes variables and function declaration. Specially for function'''const''' is very important. Use it always if a function doesn't change the object.
     22{{{
     23SomeClass.h:
     24    int getSomeNumber() const;
     25
     26SomeClass.cc:
     27    int SomeClass::getSomeNumber() const
     28    {
     29        return myValue_;
     30    }
     31}}}
     32Read [wiki:PerformanceTips#constfunctions this] for more information.
     33
     34=== Reference ===
     35Use pass-by-reference over pass-by-value when possible:
     36{{{
     37public:
     38    void setPosition(const Vector3& position);
     39    const Vector3& getPosition() const;
     40
     41private:
     42    Vector3 myPosition_;
     43}}}
     44Read [wiki:PerformanceTips#constreference this] for more information.
     45
     46=== Initialization ===
     47 * All class variables should be initialized to a sane value in the constructor.
     48 * Prefer initialization to assignment in constructors.
     49 * Initialize pointers with 0 or 'new ClassName'.
     50
     51=== Pointer ===
     52 * When a member value pointer is deleted, it should be set to 0.
     53 * Don't forget to delete objects in the destructor if your class is responsible for the object.
     54
     55=== virtual ===
     56 * If a base class has virtual functions, derived classes should have the "virtual" keyword repeated for those functions.
     57 * Don't use virtual functions in the constructor of the same class
     58
     59----
    1060
    1161== Files ==
     
    80130#endif /* _ClassName_H__ */
    81131}}}
     132
     133----
    82134
    83135== Comments ==
     
    172224}}}
    173225
     226----
     227
    174228== Naming Conventions ==
    175229
     
    291345}}}
    292346
     347----
    293348
    294349== Indentation ==
     
    311366}}}
    312367
     368----
     369
    313370== Whitespaces ==
    314371Use one space after each keyword and enclose operators with 2 of them: {{{ if (a + b < c) }}}
     
    333390
    334391
     392----
     393
    335394== Statements ==
    336 
    337395
    338396=== Access Modifiers for Classes ===
     
    359417Only loop control statements must be included in the for() construction.
    360418
     419
     420----
    361421
    362422== Layout ==
     
    426486}}}
    427487
     488----
     489
    428490== Special Implementations ==
    429491=== Use STL Libraries ===
    430492Use STL (standard template library) implementations of common abstract data structures like lists, arrays, stacks, queues, never implement your own!
    431493
    432 == General Topics ==
     494----
     495
     496== Compiling ==
    433497 * different build targets possible (for subprojects)
    434498 * different make options (make-dbg, make-opt)
    435499 * unit test supported (in debug mode)
    436500 * compiler mode: warnings being treated as errors
     501
     502----
    437503
    438504== Code Reviews ==