Chapter 8. Programming Guidelines
Prev |  | Next

# Chapter 8. Programming Guidelines

## 1. Generalities

The presentation of a program indicates the quality of programming. This section relates to the common recommendations for the Tulip project. Each new programmer has to follow the expressed rules.

In the header files, the programmer should write a headline containing : his name with personal email adress (for students), the date of the last modifications, a reminder of the licence GPL[1] and the references of the code (for example, an algorithm). Header files must include a construction that prevents multiple inclusions. The convention is an all uppercase construction of the file name, the h suffix and prefixed by “Tulip”, separated by an underscore.

    #ifndef Tulip_MYTYPE_H
    #define Tulip_MYTYPE_H

    ...

    #endif // Tulip_MYTYPE_H

The organisation of files must be comprehensible. New module leads to a new set of files : a `*.cpp` and a `*.h` named with the name of the type. If the structure implicates that all methods are inline, the creation of a `.cxx` file is better than a `.cpp` file. The `cxx` should be included at the bottom of the header file. None implementation is in the header file. In the Tulip hiearchy, the cxx files are in a directory “cxx” in the header location.

The indentation is an important part for a easy reading in a file and a best understanding. Code must be properly indented to show the syntactic structure of the program. It is useless to space out excessively the code. A conventional indentation is just necessary. None useless TAB or spaces. The { caracter for the opening of a method or a function must be at the end of the line, not in following line. Each new fitted block of program implies a new shift for the indentation.

Each new module inserted in the Tulip library must be included in the namespace `tlp`. It is necessary in order to prevent eventually incompatibilities.

    namespace tlp{

    /* code inserted */

    }

Tulip is dependent of the STL[2]. It provides a set of performing objects that you should use : vector, map, string, ... It exists two ways to use it. In the `.h` or `.cxx` files, you should preface them with the `std` namespace (e.g. `std::string s;`). You will refer them with the fullname : namespace and class name. For the `.cpp` files, you can use the short name if you insert the line at the top of your document `using namespace std;`.

In a header file (`.h` or `.cxx`) :

    class MyClasse{
      public:
        Myclasse();
        ~MyClasse(){}
        void draw();

      private:
        std::string mystring;
    };

In a source file (`.cpp`) :

    using namespace std;

    MyClasse::MyClasse(){
        mystring = "Hello world";
    }
    void MyClasse::draw(){
        cout<<mystring<<endl;
    }

[1] General Public License

[2] Standard Template Library

Prev |  | Next
6. GlScene | Home | 2. Naming conventions