Basic rules#
Language#
English will be used for code comments and identifiers. Therefore, code such as:
// calcul de contraintes
//
contrainte=strain*elas;
will be avoided.
*.h files#
*.h files will be organized according to the following template:
#ifndef __File_name__
#define __File_name__
Do not forget to insert a #endif at the end of the file. For
instance if the file is called String.h it should contain
#ifndef __String__
#define __String__
...
#endif
This is mandatory in order to avoid to include the same file several times. Classes will then be defined. Other header files can also be included when it is necessary. Note that if a pointer or a reference is used, it is not necessary to include the header file where the class is defined. Therefore
#include <String.h>
...
void myfunction(const STRING&);
can be replaced by
class STRING;
...
void myfunction(const STRING&);
This decreases the number of interdependencies between header files and
can be very useful to speed up the make.
*.c files#
It is recommended to put together in a single file all member functions of a class, according to the following template:
#include <...> // C++ : alphabetical order
...
#include <...> // Zebulon : alphabetical order
// implementation of class X
CREATE AND INITIALIZE STATIC DATA MEMBER[S]
CONSTRUCTOR[S]
DESTRUCTOR
MEMBER FUNCTION[S]
FRIEND FUNCTION[S]
// implementation of class Y
...
include will be inserted at the beginning of the file by
alphabetical order. C++ files and Z-set will be separated.
Names#
Give explicit names to variables, classes and functions.
Use enum rather than integers. For example:
switch(type) {
case 1 : do_ps(); break;
case 2 : do_pe(); break;
};
is better written as:
switch(type) {
case PLANE_STRESS : plane_stress(); break;
case PLANE_STRAIN : plane_strain(); break;
};
Global variables#
Avoid global variables. Rather use static class data members. 1See Reference manual for the list of global variables.
Static variables#
Static (non-const) data variables should be avoided, as they can cause problems in parallel applications where multiple processes may access the same variable simultaneously.
Enumerations#
Do not create global enumerations. Attach them to classes.
class DOF {
....
public :
enum DOF_TYPE {U1,U2,U3,EZ,R1,R2,R3,PR,TP};
...
};
They are used as follows:
ARRAY<DOF::DOF_TYPE> dof_names(2);
dof_names[0]=DOF::U1; dof_names[1]=DOF::U2;
Comments#
Comments should be written according to the specific C++ syntax (i.e.
//) instead of the C syntax (i.e./* */). For example:should be replaced by
Please write a self–commented program. Instead of
write: