-
Notifications
You must be signed in to change notification settings - Fork 9
Style Guidelines
Unfortunately, there is no one universal coding standard for C++. Depending on who you ask you will find different rules on how to style things. As a base for this discussion I refer you to C++ Coding Standard. This guide has in general some of the more common style choices we have in this software. The list below details some of the exceptions and summaries to this style.
##Classes
- Classes are things:
ExampleClass - Methods/functions are actions :
DoSomething() - Implementation of classes in files with the same name as the class:
VandleProcessordefined in VandleProcessor.hpp/cpp - Only ONE Class per file.
- Private class variables and members are appended with an underscore
myVariable_ - The order of class methods/variables will be public, protected, private
##Naming Things
- New Experiment Processors will be named after the experiment number, identifier, etc. Failing that use the facility and the date. Examples: IS600Processor, JaeaDec2015Processor, etc.
- New Detector Processors will be named after the type of detector that they are processing. Ex. VandleProcessor, DssdProcessor, etc. make sure that you are not duplicating things that can be handled in other processors
- Variables have names like
myVariable - Namespaces like
thisNamespace - Acronyms only have the first letter capitalized:
DssdProcessor. Exception if starting a variabledssdHit. - Global CONSTANT variables can have forms like
CONSTANT_VARIABLE - Fortran functions called as
func_() - Files with extensions
.cpp,.hpp,.f,.xml - Generic index variables use
i,j,kor more explicit names such asmod, ch; if you need more, consider reorganizing your code - Enumeration types like
EColorswith members{BLUE, RED, ORANGE} - Typedefs with simple names like
word_t - Spectrum IDs use namespaces as appropriate and constant names like
D_ENERGY(1D) orDD_TIME_ENERGY(2D, time (y) vs. energy (x))
##Includes
-
They take the following form
__FILENAME_HPP__and must be in every header. -
Includes should be ordered by system wide and then code specific and be alphabetical.
-
C include and C++ includes should be separated
#include <iostream> #include <vector> #include <cmath> #include "ChanEvent.hpp"
##Formatting
-
When using curly braces ({}) the opening brace will be on the same line as the call:
if(dosomething) { //do something useful here } -
Indentation will be done with 4 spaces, do not use a tab character. Ensure that your editor is setup to replace tabs with spaces!!
-
Lines are no more than 80 characters long.