-
Notifications
You must be signed in to change notification settings - Fork 13
Conventions
To prevent git conflicts and ugly histories, please always format your code with the eclipse formatter ctrl+shift+f. Unfortunately, unlike for Java projects, eclipse does not provide an automatic formatting at saving a file. Therefore please try to get used to always press a combination of ctrl+s and ctrl+shift+f!
The L1 and L2 specific algorithms should be implemented within the folders l1 and l2. Code that is shared by L1 and L2 should be stored in common. Within all these three folders code related to one detector should always be stored in a detector specific folder as in l1/straw/ unless the code is supposed to be reused by other detectors.
Here's a rough list of conventions I try to stick to:
- CamelCase (don't use '_' in Methode/Variable names except in following two points)
- Instance variables are lower case and end with
_e.g.int someVar_; - Global constants are written uppercase with
_between every word like#define SOURCE_ID_L0TP 0x40 - Class names are capitalized as in
class SomeClass { - Method names are in lower case e.g.
void doSomething() {
Use c++11 syntax and objects like in following examples:
- Range-based loops:
std::vector<int> v = someFunction();
for (int i: v) {
std::cout << i << std::endl;
}
- Type inference:
auto myMap = getSomeMap();
for (auto& keyValue : myMap) {
std::cout << "Key: "<< keyValue.first << ", value: " << keyValue.second << std::endl;
}
- Use move semantics and rvalue references:
void addElement(Element&& e) {
myVector.push_back(std::move(e));
}
-
Use
std::unordered_setandstd::unordered_mapwith O(const) access time instead of the binary tree implementations (std::setandstd::map) with O(n*log(n)) access time if you have large collections. -
Consider using
std::unique_ptr,std::shared_ptrandstd::make_shared -
Nested constructors:
class MyClass {
int num_;
public:
MyClass(int theNumber) : num_(theNumber) {}
MyClass() : MyClass(23) {}
};
- Use
nullptrinstead ofNULL - Initializer lists:
MyStruct vector = {0.23f, 42.5f}; - See more at wiki