CodingRules
From Gnoll's Wiki
Coding Rules define a frame for programmers on Gnoll to speech the same language. Coding Rules are choices. They might change from projet to projet, but for a given projet, it is important to respect them.
As coding rules are being written and discussed in the mailing list, they are nor complete nor definitive. They are sorted in Adopted and Being discussed categories.
Contents |
Adopted
Adopted rules are rules that have been discussed in the Gnoll mailing list. They are considered mandatory and submitted code should follow them (or explain why it can't follow a given rule).
- Every method and every member in a class must be documented in Doxygen format.
- This implies that any modification to the code must be made with a careful update of comments.
- While implementing a class, the order of accessibility sections must be public, then protected, then private. The methods are written first, followed by member variables.
- #include keywords in header files should be put inside the inclusion guard.
- Line spacing should not exceed one line.
- Line should not exceed 100 characters.
- Beginning and end of blocs ({ and }) are put alone in their line.
- Eg :
if (condition)
{
.. code ..
}
else
{
.. code ..
}
- Naming of classes should not use abbreviation. Use plain and descriptive names. Eg : correct name FiniteStateMachine, incorrect name FSM.
- Exception if for describing something that is already and externally described by its abbreviation. Eg : AVIStreamReader
- Classes have no prefix showing that they are classes (no leading C)
- In argument lists, there is no space at the beginning and and of the list. Eg : function(int parameter) is correct, function( int parameter ) is not.
- Interfaces : prefixing by Abstract (as in C++, the Interface concept is implemented as abstract classes).
- Member variables : prefix by 'm_'.
- Include order : like standard headers, extern librairies headers, project headers
- Corresponding .h is the first of includes in .cpp
- Methods with more thant 1 word should be name like : void thisIsMyMethod();
Being discussed
Discussed rules are not considered fixed yet. They are still being discussed in the mailing list. A summary of what has been said on them can be added as sub-items.
- Discussion : classes should have a maximum length for their names ? What length ?
Templates
Header file
/***************************************************************************
* Copyright (C) 2007 by Paf *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/*--------------------------------Include----------------------------------*\
| Description ... |
\*-------------------------------------------------------------------------*/
#ifndef __INCLUDE_H__
#define __INCLUDE_H__
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <boost/shared_ptr.hpp>
#include <libxml++/libxml++.h>
#include <glibmm/ustring.h>
#include "../../dynamicobject/include/string.h"
#include "../../dynamicobject/include/float.h"
#include "../../dynamicobject/include/set.h"
#include "../../dynamicobject/include/cdynamicobjectproxy.h"
#include "../../core/include/cpoolthreads.h"
#include "../../core/messages/include/messagetype.h"
#include "../../core/messages/include/listener.h"
#include "../include/cpage.h"
using namespace std;
namespace Gnoll
{
namespace Scene
{
/**
* Include
*/
class Include
{
public:
/**
* This is a constructor
*/
Include();
/**
* This is a destructor
*/
~Include();
/**
* Foo bar ahahahah <br/>
* continue description here :) <br/>
* @param param1 Description
* @param param2 Description
* @return Description
*/
int fonc1(double param1, double param2);
private:
int m_attribut1;
double m_attribut2;
};
}
}
#endif // __INCLUDE_H__
Source file
/***************************************************************************
* Copyright (C) 2007 by Paf *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "include.h"
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <boost/shared_ptr.hpp>
#include <libxml++/libxml++.h>
#include <glibmm/ustring.h>
#include "../../dynamicobject/include/string.h"
#include "../../dynamicobject/include/float.h"
#include "../../dynamicobject/include/set.h"
#include "../../dynamicobject/include/cdynamicobjectproxy.h"
#include "../../core/include/cpoolthreads.h"
#include "../../core/messages/include/messagetype.h"
#include "../../core/messages/include/listener.h"
#include "../include/cpage.h"
using namespace std;
namespace Gnoll
{
namespace Scene
{
Include::Include()
{
}
Include::~Include()
{
bool cond1 = true;
bool cond2 = true;
if(cond1 == cond2)
{
// ...
}
while(cond1)
{
// ...
}
do
{
// ...
} while(cond2);
fonc1(5, 7);
return 0;
}
int Include::fonc1(double param1, double param2)
{
}
}
}