Actions
C++ coding rules¶
Usefulness¶
The following C++ code rules aim to keep the same plugin structure whatever the developer.
General points¶
- Indentation
	
- 2 space characters (no tab),
 - Left brace at the beginning of the line (no Java-style using the left brace at the end of the line).
 
 
 if (true)
 {
   // Good Indentation
 }
 else
 {
 // Bad indentation
 }
	- No space between the latest character on a line and the final semicolon.
 
int maPremiereVariable = 1; // Good int maSecondeVariable = 1 ; // Bad
- The character '*' for a pointer and '&' for a reference must be stuck to the related type or variable.
 
MyClass* pointeur1 = new MyClass(); // Good MyClass * pointeur2 = new MyClass(); // Bad MyClass *pointeur1 = new MyClass(); // Bad
- Each new parameter of a function must be preceded by a space. Furthermore, there mustn't be any space just after the left or right parenthesis.
 
int maVariable = maFonction(param1, param2, param3); // Good int maVariable2 = maFonction(param1,param2,param3); // Bad int maVariable2 = maFonction(param1 , param2 , param3 ); // Bad
- Don't hesitate to follow a very strict indentation, even if when the source code can be composed of a single line. This method will make the debugging easier.
 
 if(curMaterialPair)SAFE_DELETE(curMaterialPair); // Bad
 if (curMaterialPair)
   SAFE_DELETE(curMaterialPair);                  // Good
 if (curMaterialPair)                             // Also good
 {
   SAFE_DELETE(curMaterialPair);
 }
	
Class definition¶
For each definition of a class, the following structure must be followed :
 class MyClass
 {
 // Member variables, typedefs and enums are defined here
 public:
 protected:
   int maVariableMembre; // member variable sample.
 private:
 // Member functions and methods are defined here
 public:
   /*!
   Constructor sample
   */
   MyClass(int newVal);
 protected:
 private:
 };
	Using this way, it's easy to identity the different elements from a class, and their respective access level (public, protected or private).
Updated by ModularMix about 14 years ago ยท 1 revisions