|
| 1 | +# Style Guide |
| 2 | + |
| 3 | +To ease development we agree on a basic code style described as follows. |
| 4 | + |
| 5 | +## Naming Convention |
| 6 | + |
| 7 | +In general, abbreviations should only be used if they are absolutely unambigious and would save a |
| 8 | +lot of horizontal space. |
| 9 | +In case one hesitates whether to abbreviate a variable or not, rather not do it! |
| 10 | + |
| 11 | +Always use underscores (`_`) as word separation. |
| 12 | + |
| 13 | +* __Files__ |
| 14 | + |
| 15 | + Due to systems which do not distinguish between upper and lower case in file and path names, |
| 16 | + always use lowercase for file names and directories. |
| 17 | + |
| 18 | + Header files should be named after the main/central class contained in. |
| 19 | + For example, a class `MyClass` should be in a header file called `my_header.hpp`. |
| 20 | + Separate words by underscores. |
| 21 | + |
| 22 | +* __Namespaces__ |
| 23 | + |
| 24 | + Should always be lowercase and not too long. |
| 25 | + |
| 26 | +* __Class Names__ |
| 27 | + |
| 28 | + Should start with a capital letter and use _CamelCase_. |
| 29 | + |
| 30 | + Abstract classes should start with a capital `I` denoting an _interface_. E.g. `ISweeper` in |
| 31 | + `i_sweeper.hpp`. |
| 32 | + |
| 33 | +* __Function Names__ |
| 34 | + |
| 35 | + Should only consist of lowercase letters and underscores separating words. |
| 36 | + |
| 37 | +* __Variable Names__ |
| 38 | + |
| 39 | + Should always be lowercase using underscores as word separation. |
| 40 | + Member variables of classes should start with `m_`. |
| 41 | + Constants should all be uppercase with undersocres as word separation. |
| 42 | + |
| 43 | +* __Template Parameter__ |
| 44 | + |
| 45 | + In case, most template parameters denote a certain type, append a capital `T` to the name of the |
| 46 | + template parameter. E.g. |
| 47 | + ~~~{.cpp} |
| 48 | + template<typename typeT> |
| 49 | + int my_func(std::vector<typeT> &vec); |
| 50 | + ~~~ |
| 51 | + |
| 52 | + |
| 53 | +## Techniques |
| 54 | + |
| 55 | +### Includes |
| 56 | + |
| 57 | +System headers and those from third party libraries should be included using angular brackets. |
| 58 | +Headers from our library should be included using double quotes. |
| 59 | + |
| 60 | +For headers included via angular brackets, the preprocessor will search through all paths given via |
| 61 | +the `-I` parameter. |
| 62 | +While for includes with double quotes it will only look in the directory of the header including |
| 63 | +the included file. |
| 64 | +Only when there is no such header in there, the preprocessor will go on with the behaviour for |
| 65 | +angular brackets. |
| 66 | + |
| 67 | +### Define Guards |
| 68 | + |
| 69 | +Use `#define` guards in header files to prevent multiple inclusion. |
| 70 | +The variable defined should be derived from the header file name itself. |
| 71 | +For example, a header file `my_header.hpp` in the folder `PFASST/src/subfolder` should have the |
| 72 | +following define guard: |
| 73 | + |
| 74 | +~~~{.cpp} |
| 75 | +#ifndef PFASST__SUBFOLDER__MY_HEADER_HPP |
| 76 | +#define PFASST__SUBFOLDER__MY_HEADER_HPP |
| 77 | +// file content |
| 78 | +#endif // PFASST__SUBFOLDER__MY_HEADER_HPP |
| 79 | +~~~ |
| 80 | + |
| 81 | +Always include the library name and at least one subfolder (if applicable) to prevent possible |
| 82 | +multiple defines in files with the same name but in different folders. |
| 83 | + |
| 84 | +### Encapsulation / Clean API |
| 85 | + |
| 86 | +We want to provide a clean API, thus we use encapsulation wherever possible. |
| 87 | +For classes, we prefer private member/data variables and provide access to them via getter/setter |
| 88 | +methods. |
| 89 | + |
| 90 | +### C++ Feature Set |
| 91 | + |
| 92 | +We agreed on using the "most common" C++11 features. |
| 93 | +These are: |
| 94 | + |
| 95 | +* `auto` keyword |
| 96 | +* `shared_ptr` and `unique_ptr` |
| 97 | +* type traits |
| 98 | +* static asserts |
| 99 | +* Rvalue references and move semantics |
| 100 | +* `decltype` |
| 101 | +* delegating constructor |
| 102 | +* `constexpr` |
| 103 | +* right angle bracket (`vector<vector<T> >` vs. `<vector<vector<T>>`) |
| 104 | + |
| 105 | +@todo Check the list of used/required C++11 features and possibly extend it by a list of minimum |
| 106 | + compiler versions supporting the features. |
| 107 | + |
| 108 | + |
| 109 | +## Documentation |
| 110 | + |
| 111 | +Document your code. |
| 112 | + |
| 113 | +We use [Doxygen] for generating the documentation webpage. |
| 114 | +You can use pretty much all the features, Doxygen provides, including [MathJAX] for formulas and |
| 115 | +[Markdown] for easy text formatting. |
| 116 | + |
| 117 | + |
| 118 | +## Formatting |
| 119 | + |
| 120 | +In short: no tabs, 2 spaces, sane indent-continuation. |
| 121 | + |
| 122 | +We provide a configuration file for the code beautifier [uncrustify] which does a pretty good job |
| 123 | +to ensure consistent formatting of the source files. |
| 124 | + |
| 125 | + |
| 126 | +[Doxygen]: http://www.stack.nl/~dimitri/doxygen/index.html |
| 127 | +[MathJAX]: http://www.stack.nl/~dimitri/doxygen/manual/formulas.html |
| 128 | +[Markdown]: http://www.stack.nl/~dimitri/doxygen/manual/markdown.html |
| 129 | +[uncrustify]: http://uncrustify.sourceforge.net/ |
0 commit comments