2. Code Convention




"A major benefit of object-oriented programming languages like C++ is the degree of reuse that can be achieved in well-engineered systems. A high degree of reuse means that far less code must be written for each new application; consequently, that is far less code to maintain." (G.Booch).

The set of rules listed here are the only 'imposed' rules which have been adopted for the development of Geant4. We think they might become useful also for those users who will develope C++ code for applications related to Geant4 and, why not?, in general !

2.1 Introduction

Geant4 as object-oriented toolkit is thought to be an integration of components (sets of classes) which are specific to the HEP applications or part of general foundation class libraries, math libraries (commercial or free) already implemented and distributed world-wide, useful as building blocks for a wide variety of applications. Even within HEP, the reusability of object-oriented software across different laboratories and between different experiments will be essential.

As an object-oriented toolkit, Geant4 can be certainly extended and refined by physicists and experts all over the world, who may have used or will use their own coding conventions and rules, different from each others. It is and has been then important not to impose too fixed rules or style-conventions for a world-wide collaboration like GEANT4, but just flexible and adequate guidelines for programming and coding styles.

"C++ was designed to support data abstraction and object-oriented programming in addition to traditional C programming techniques. It was not meant to force any particular programming style upon all users" (B.Stroustrup).


2.2 Programming guidelines

The programming guidelines are the ones which refer to the way of using the features of the programming languages. They have to do with things like the adhesion to the object oriented paradigm (data-hiding, encapsulation, etc ...), the performance and portability.


2.3 Coding-style conventions

The coding-style guidelines are the ones which refer to the editing styles of the source code. They have to do with things like the code maintainability and readability.


2.4 Coding-style for writing a Geant4 application


2.5 Programming Suggestions learned from experience

Here is a list of rules/hints which we could collect after all periodical sessions of QA/QC on the developed code. These "hints" have been made public to Geant4 developers in order to avoid the most common mistakes and improve the quality of the code.