Coding Style
This section lists reccomendations for coding style used in Orion project.
Coding style used in FelixClient
code (in FELIX project) with some minor modifications is taken as the baseline for the project. Some general desriptions with particular examples are presented below.
Header files
For C++
files use .hpp
and .cpp
extensions,
and for C
files use .c
and .h
,
Filenames are lowercase with underscore, for example npoint_gain.hpp
.
Guard headers files with #pragma once
statement.
For more details why it is preferrable, read [this].
Naming conventions
Class names use camel
notation, like DataProc
or FelixController
.
Functions and variables names are lowercase with underscore, like send_data()
or mem_buff
,
unless there is an abbreviation or important reason to use camel
notation (for example, to match chip documentation).
Use member variables without m_
prefix.
Adding m_
prefix does not improve understandability of your code,
while it makes the code less readable.
If code is hard to follow, and it is not clear where local or member variables are used,
most likely the code has problems with architecture; try to recode it in a better way.
This, however, does not mean that one should not use prefixes.
If you want to indicate that an object is string or pointer, use str_
or ptr_
.
Try to avoid very long names for variables or functions.
Indentations
For compatibility with different frameworks, indentations should be made with spaces and not with tabs.
For C++
code 2-space identation is used to have less indentation in nested loops.
For scripting and configuration files, like python
or bash
, 4-spaces indentation is used.
Namespaces
Namespaces should be favored instead of prefixing names.
For example, instead of using classes ItkpixDataProc
and StarDataProc
for pixel and strips,
one could use DataProc
definitions within itkpix
and star
namespaces accordingly.
Inside the namespace class can be accessed as DataProc
.
From outside class can be referred as itkpix::DataProc
.
Examples of the code
hpp header file
#pragma once
namespace itkpix {
class DataProc {
public:
void load_data(const std::vector<uint32_t> &data);
uint32_t get_trig_count() {
return trig_count;
}
private:
uint32_t trig_count = 0;
};
} // itkpix