Basic & Extended Examples Coding Guidelines
Version 2.1 Proposal
Name conventions
- Class names are defined within a single namespace, specific to each example. Eg. B1, B2, etc. for the basic examples. Class names without a prefix can be still defined in the categories where this convention is already in use.*
- Class member functions start with an upper case letter.
- Class data members start with a prefix
"f"
followed with an upper case letter. This convention makes easier to understand the code. - Local variables and functions argument names start with a lower case letter except for the names starting with known acronyms in capital case letters.
Coding rules
- Declare overriding virtual functions in the header files with keyword
override
. - Initialize class data members using default member initializer in the class definition (.hh). Both initialization with braces or assignment are possible. This prevents from use of uninitialized values.
- Do not introduce dummy functions or classes if they have no use in the example.
- The UI commands defined in the example should be used in the cdash test macro(s) as much as possible.
Style rules
- Avoid using long lines (more than 100 characters) where possible.
- Avoid using tabulators.
- Each function implementation in the .cc file should be preceded by the agreed separator line.
- Avoid using more than one empty lines or personalized separators in the code.
Documentation
- Each example is provided with a
README
text file and its modified version.README.txt
for automatic generation of the Web documentation with Doxygen. The latter differs from the former only by the modifications needed for a correct representation of the file on the Web. - The files with C++ code start with a standard header including Geant4 copyright and a file description. The comment lines with a file description start with
///
(instead of standard//
) in order to be recognized by Doxygen, on the first line followed by the keyword\file
. - Each class contains a description of the class functionality placed just before a class definition in the class header file (.hh) The comment lines with a class description start with
///
(instead of standard //) in order to be recognized by Doxygen. - All macros provided with the example should be documented in
README
.
Application conventions
- It is recommended to define materials with using NIST manager unless there is a specific reason for explicit material definition.
- It is recommended to use the physics list classes and physics builders provided in Geant4 unless there is a specific reason for using an explicitly defined physics list.
G4UIExecutive
should be instantiated at the same beginning ofmain()
if interactive mode is enabled, just after arguments processing if present. This makes possible to handle the output and eventual exception via the Geant4 UI since the beginning of running example.
These rules should be applied in addition to the Geant4 Coding Guidelines for developers: http://geant4.web.cern.ch/geant4/collaboration/coding_guidelines.shtml