Basic rules#
Language#
English will be used as programming language. Things like :
// calcul de stress
//
contrainte=strain*elas;
will therefore 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]
CREATOR[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.
switch(type) {
case 1 : do_ps(); break;
case 2 : do_pe(); break;
};
is usefully replaced by
switch(type) {
case PLAIN_STRESS : plane_stress(); break;
case PLAIN_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 data variables (non-const) should be avoided. They cause problems in parallel applications where one instance of the variable may be manipulated by multiple processes at the same time.
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 in the following manner:
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 (ie
//
) instead of the C syntax (ie./* */
).should be replaced by
Please write a self–commented program. Instead of
write: