|
Here are gathered some good practice for coding.
|
|
Here are gathered some good practice for coding.
|
|
|
|
|
|
General rules:
|
|
**General rules:**
|
|
* Add comments to the code (ideally, almost each line should be commented)
|
|
* Add comments to the code.
|
|
* Always use "const" keywords where needed
|
|
* Always use "const" keywords where needed.
|
|
* Promote complete names when possible for the variables, in particular when used in several places in the code (example: fv => localPorosity)
|
|
* Promote complete names when possible for the variables, in particular when used in several places in the code (example: fv => localPorosity).
|
|
* Variables are named using "camel case" rule (e.g. exampleOfVariableName)
|
|
* Variables are named using "camel case" rule (e.g. exampleOfVariableName).
|
|
* Avoid public variables and functions in class
|
|
* Avoid as much as possible public variables and functions in class.
|
|
|
|
|
|
Name rules:
|
|
**Name rules:**
|
|
* Class name start with an uppercase (e.g. Example)
|
|
* Class names start with an uppercase (e.g. Example)
|
|
* Internal variables of a class start with an underscore and a lowercase (e.g. _example)
|
|
* Internal variables of a class start with an underscore and a lowercase (e.g. _example)
|
|
* Class functions start with a lowercase (e.g. example)
|
|
* Class functions start with a lowercase (e.g. example)
|
|
* Access functions "get/set":
|
|
* Access functions "get/set":
|
|
* getRefToExample() : can be used or set by reference a variable value that exists (or copy-paste its value);
|
|
* getRefToExample() : can be used to get the reference / the pointer of a variable in order to modify its value;
|
|
* getConstRefToExample() : idem but in read-only access;
|
|
* getConstRefToExample() : idem but in read-only access;
|
|
* getExample : use it when you want to return an object that may be not exist;
|
|
* getExample : use it when you want to return a ariable value or the pointer towards an object;
|
|
* setExample : set a value that may be not exist or through a more complex function than just an assignment
|
|
* setExample : set a value that may be not exist or through a more complex function than just an assignment;
|
|
|
|
|
|
|
|
|
|
|
|
**Doxygen:**
|
|
|
|
* Installation:
|
|
|
|
* download with your package manager "doxygen" and "doxygen-gui" and "graphicviz".
|
|
|
|
|
|
|
|
* Comment usage:
|
|
|
|
* "//!" is related to a comment of "level 1" appearing in Doxygen. It corresponds to general comments (related to the interface, the purpose or the goal of the function but not to the practical implementation (otherwise, use "//" instead)).
|
|
|
|
* "///" is related to a comment of "level 2" appearing in Doxygen.
|
|
|
|
* "//" is related to a practical implementation comment that is not visible inside Doxygen (i.e. giving some practical details of the implementation)
|
|
|
|
* "//! \todo bla bla bla bla" is a Doxygen tag for remaining tasks that can be highlight and gathered in a particular section in Doxygen.
|
|
|
|
* Class and function documentation:
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|