Changes between Version 15 and Version 16 of CodingGuidelines


Ignore:
Timestamp:
Mar 29, 2012, 11:00:18 AM (13 years ago)
Author:
FrederikHeber
Comment:

added section on not use #define for const

Legend:

Unmodified
Added
Removed
Modified
  • CodingGuidelines

    v15 v16  
    258258}}}
    259259This is more efficient that setting the value in the constructor's body because the constructor of ''test'' gets called with the correct value right away instead of default constructor and then assignment operator.
     260
     261=== Don't use #define for const values === #code-good-bad-const-defines
     262
     263Creating constant variables as
     264{{{
     265#define three 3.
     266}}}
     267is evil because:
     268 * in the debugger you only see ''3.'' not ''three''. Hence, you have significantly less information and a harder time to understand the code.
     269 * very strange errors may occur of a define is used as an argument in another define.
     270
     271Instead use:
     272 * '''Enum-Hack:''' enum {Num = 2}; for integers, used very frequently in the context of Template Meta Programming
     273 * '''Const variables''' simply declare a (even global) const variable to contain the value.
     274