-
Notifications
You must be signed in to change notification settings - Fork 56
Coding conventions and style guide
In general, every .cc
file should have an associated .h
file. There are some common exceptions, such as unittests and the .cc
files containing just a main()
function.
A correct use of header files can make a huge difference to the readability, size and performance of your code.
The following rules will guide you through the various pitfalls of header and source files.
- Use forward declarations where possible.
- In
#ifndef
-#define
guards, use the name of the class in capital letters +_H
at the end. - Use trailing underscores for data members.
- Use lower case letters and underscores for variable names (e.g.,
drift_length
rather thanDriftLength
). - Use capital letters and no underscores for function names (e.g.,
DefineMaterials()
). - Add a brief description of the purpose of the class (also in
.cc
files). Use an existing class as an example of the format. - Try not to copy and paste the
#include
from another class, because you'll end up with a lot of them that you'll not use. Keep them to the minimum set needed by your code.
In macro files, group the commands of the same class and use the same order as in one of the existing files.
The length of each line of code should be at most 80-100 characters. A developer should not change the indentation of someone else's code, unless the line is longer than 100 characters.
Since it is quite inconvenient to have long names in the output files, the names of the geometry volumes must be kept under 20-30 characters. Brevity is good.
When using the G4Exception
class use the following convention:
G4Exception("[ClassName]", "Function()", Exception, "error message")
We are using common conventions described, for instance, in this page.
NEXUS tags have this format: vX_Y_Z. X is incremented when a major change is introduced, or when it breaks backward compatibility. Y is incremented when a new functionality is added to the code (for instance, a new geometry, or a new generator) and Z is incremented when a bug of an already existing functionality is fixed.
- Home
- Installation
- Contributing to NEXUS
- Code documentation
- Releases
- User guide