Changes between Version 7 and Version 8 of CodingRules


Ignore:
Timestamp:
11/26/13 15:34:36 (11 years ago)
Author:
tbretz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CodingRules

    v7 v8  
    28280. For proper documentation, please have a look at other classes. Note that FACT++ and Mars style is slightly different. Mars is using THtml with some Mars specific setup, FACT++ is using doxygen.
    29290. Never define constants as preprocessor directives. Generally avoid preprocessor directives.
     30o. omit else in constructions like *if (...) return x; [else] ....*
     310. Source files have the extension cc, header files the extension h, C source files just c.
     320. Operators +=, -=, etc. are preferable over constructions like x=x+, x=x-, ...
     330. If you omit intentionally a break in a switch statement (*fallthru*) add a comment
     340. Sometimes including system headers is not identical for all operating systems, comments might help
     350. Try to avoid using dynamic allocation whenever possible: "int i=5; /* do something with i*/; /* i runs out of scope */" is preferred over "int *i = new int; *i=5; /* do something with i */; delete i;" Although this example sounds ridiculous, the same is true for every class instance you use.
    3036
    3137== Example ==
    3238{{{#!C++
     39#ifndef MARS_Complex
     40#define MARS_Complex
     41
     42#include <math.h> // needed for sqrt on Ubuntu 10.14
     43
     44class Complex
     45{
     46private:
     47    double fRe;
     48    double fIm;
     49
     50public:
     51    Complex(double re, double im)
     52        : fRe(re), fIm(im)
     53    {
     54    }
     55   
     56    double Modulus() const
     57    {
     58        return sqrt(fRE * fRe + fIm * fIm);
     59    }
     60
     61    bool Foo(int a, int b)
     62    {
     63        for (int i=0; i<b-a; i++)
     64        {
     65            if (i<b)
     66                bar(i);
     67            else
     68            {
     69                bar(i);
     70                bar(b);
     71            }
     72        }
     73
     74        const int c = a + b;
     75        switch (c)
     76        {
     77        case 0:
     78           // Code goes here
     79           return false;
     80        case 1:
     81        case 2:
     82           // Code goes here
     83           return false;
     84        default:
     85           // Code goes here
     86           return true;
     87        }
     88
     89        return true;
     90     }
     91};
     92
     93#endif
    3394}}}
    3495