To ensure that the different modules developed for the ARCANE platform have a certain homogeneity, this document proposes a set of coding rules.
General
- the language used is C++20
- file encoding must be 'UTF-8' with BOM at the beginning of the file. The first line of each file must be as follows: // -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
- all comments use the Doxygen product syntax to be able to extract paper or hypertext documentation directly from the source code,
- all identifiers are written in English.
- indentations are done with 2 spaces. There must be no tab characters in the code.
Source Files
- all source files are formatted the same way and all begin with a header describing the file name, the modification date.
- the actual code follows. Each identifier must be commented and functions must be separated by two lines of comments. For example:
int
functionExample(int argc,char** argv)
{
return argc/2;
}
Variables
- variable names are always in lowercase. If the name is composed of several logical words, each word is separated by the underscore character. For example:
volume
list_of_element
cells
- To avoid any ambiguity, plural names are reserved for container type variables; all other names must be in the singular.
Classes
- Class names (
class) start with a capital letter and continue with lowercase letters. If the name is composed of several logical words, the first letter of each new word is capitalized. For example:
Component
ComponentMng
String
- Class members, in addition to respecting the same conventions as any variable, will always be prefixed by the two characters m_. For example:
m_volume
m_list_of_element
Methods and Functions
In the following, the word function will be used to designate both functions and class methods.
- function names are always in lowercase. If the name is composed of several logical words, the first letter of each new word is capitalized. For example:
numberOfElement()
assign()
- if the method name corresponds to the notion of a property (i.e., semantically equivalent to a class field) named value, the accessor must be the property name (value()) and the method to change the value must be setValue(). The accessor must not start with get. If the property is boolean, it is possible to prefix the accessor with is. For example isEmpty().
- To avoid any ambiguity, all names must be in the singular
- Function definitions must be on at least two lines:
- the first includes the return type and possibly the class name if it is a method.
- the second necessarily includes the function name.
- followed by the list of arguments on the second line and subsequent lines.
- The opening brace of the function body and the closing brace must be on a separate line:
int
function1(int argc,char** argv)
{
return argc/2;
}
Example
template<typename T>
class ConstCArrayT
{
private:
protected:
public:
typedef T value_type;
typedef const value_type * key_restrict const_iterator;
typedef const value_type * key_restrict const_pointer;
typedef const value_type& const_reference;
typedef Integer size_type;
typedef ptrdiff_t difference_type;
typedef ConstIterT< ConstCArrayT<T> > const_iter;
public:
ConstCArrayT() : m_size(0), m_ptr(0) {}
explicit ConstCArrayT(Integer s,const T* ptr)
: m_size(s), m_ptr(ptr) {}
ConstCArrayT(const ConstCArrayT<T>& from)
: m_size(from.m_size), m_ptr(from.m_ptr) {}
ConstCArrayT(const CArrayBaseT<T>& from)
: m_size(from.size()), m_ptr(from.begin())
{
}
const ConstCArrayT<T>& operator=(const ConstCArrayT<T>& from)
{ m_size=from.m_size; m_ptr=from.m_ptr; return *this; }
const ConstCArrayT<T>& operator=(const CArrayBaseT<T>& from)
{
m_size = from.size();
m_ptr = from.begin();
return (*this);
}
public:
const T& operator[](Integer i) const
{
return m_ptr[i];
}
inline Integer size()
const {
return m_size; }
inline const_iterator begin() const { return m_ptr; }
inline const_iterator end() const { return m_ptr+m_size; }
inline bool empty() const { return m_size==0; }
inline const T* base() const { return m_ptr; }
protected:
private:
const T* m_ptr;
};
Int32 Integer
Type representing an integer.