157 | This document is based on the work of
158 | B. Weinberger, C. Silverstein,
159 | G. Eitzmann, M. Mentovai
160 | and T.Landray
161 | at http://google-styleguide.googlecode.com,
162 | C++ Google Style guide, Revision 3.274
163 | under the CC-By 3.0 License
164 |
169 | Each style point has a summary for which additional information is available 170 | by toggling the accompanying arrow button that looks this way: 171 |
174 | . 172 | You may toggle all summaries with the big arrow button: 173 |184 | | 186 | |
189 | | 191 | |
226 | Though a pain to write, comments are absolutely vital to keeping our 227 | code readable. The following rules describe what you should 228 | comment and where. But remember: while comments are very 229 | important, the best code is self-documenting. Giving sensible 230 | names to types and variables is much better than using obscure 231 | names that you must then explain through comments. 232 |
233 |234 | When writing your comments, write for your audience: the next 235 | contributor 236 | who will need to understand your code. Be generous — the next 237 | one may be you! 238 |
239 |/// ... text ... 251 | /// ... text ...
///
syntax for the comments going in the
311 | Web documentation, the //
syntax for explicative
312 | comments in the code and the /* */
syntax only for
313 | the comments within one line.
314 | class
keyword.
471 | namespace
keyword.
620 | 743 | [1] Doxygen [http://www.doxygen.org] 744 |
745 | 746 | 747 | 748 | 749 | -------------------------------------------------------------------------------- /naming_formatting.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
148 | This document is based on the work of
149 | B. Weinberger, C. Silverstein,
150 | G. Eitzmann, M. Mentovai
151 | and T.Landray
152 | at http://google-styleguide.googlecode.com,
153 | C++ Google Style guide, Revision 3.245
154 | under the CC-By 3.0 License
155 |
159 | Each style point has a summary for which additional information is available 160 | by toggling the accompanying arrow button that looks this way: 161 |
164 | . 162 | You may toggle all summaries with the big arrow button: 163 |174 | |
175 | General Naming Rules
176 | Code File Names
177 | Executable Names
178 | Library Names
179 | Type Names
180 | Interface Names
181 | Variable Names
182 | Function Names
183 | Namespace Names
184 | Enumerator Names
185 | Macro Names
186 |
187 | |
188 |
191 | |
192 | Line Length One Statement Per Line Spaces vs. Tabs Function Declarations and Definitions Pointer and Reference Expressions Boolean Expressions Variable and Array Initialization Preprocessor Directives Classes Constructor Initializer Lists Namespaces Braces Horizontal Whitespace Vertical Whitespace Where to put const |
193 |
196 | | 198 | |
204 | The goal of this guide is to provide a number of rules that keep the code base manageable by enforcing 205 | consistency. 206 | 207 | It is very important that any programmer 208 | can look at another programmer's code and understand it quickly. 209 | Maintaining a uniform style and following conventions means that "pattern-matching" can be 210 | more easily used to identify different symbols and invariants. 211 |
212 |213 | Creating common, required 214 | idioms and patterns makes code much easier to understand. In some 215 | cases there might be good arguments for changing certain style 216 | rules. Nonetheless, for reasons of consistency the rules are left unchanged. 217 |
218 | 219 |220 | Note that this guide is not a C++ tutorial: we assume that the 221 | reader is familiar with the language. 222 | 223 |
224 | 225 |231 | The most important consistency rules are those that govern 232 | naming. The style of a name immediately informs us what sort of 233 | thing the named entity is: a type, a variable, a function, a macro, etc., without requiring us to search for the 234 | declaration of that entity. The pattern-matching engine in our 235 | brains relies a great deal on these naming rules. 236 |
237 |238 | Naming rules are pretty arbitrary, but we feel that consistency is more important than individual preferences in this area, so regardless of whether you find them sensible or not, the rules are the rules. 239 |
240 | 241 |353 |
o2
, and hyphenated : o2-tpc-reco-workflow
401 | O2
.
430 | MyClass
, MyEnum
.
453 | myLocalVariable
.
498 | m
.s
.m
prefix for struct members.g
.constexpr
variables are capitalized.const
.myFunction()
.
584 |
585 | get
and set
:
588 | getMyMemberVariable()
, setMyMemberVariable()
.is
or has
. my_namespace
.
658 | MyEnumType
, MyEnumValue
.
680 | MY_PROJECT_PKG1_MY_MACRO
.
757 | 781 | Coding style and formatting are pretty arbitrary. However, a good project 782 | is much easier to follow if everyone uses the same style. Individuals 783 | may not agree with every aspect of the formatting rules, and some of 784 | the rules may be hard to get used to. Even so, it is important that all 785 | 786 | project contributors 787 | follow the style rules so that 788 | 789 | they 790 | can all read and understand everyone's code easily. 791 |
792 | 793 |const
before the type when defining a const variable.
1277 | 1300 | The coding conventions described above have to be followed. However, 1301 | like all good rules, these sometimes have exceptions. 1302 |
1303 | 1304 |1338 | Use common sense and BE CONSISTENT. 1339 |
1340 |1341 | When editing code, take a few minutes to look at the 1342 | code and determine its style. 1343 |
1344 |1345 | The point about having style guidelines is to have a common 1346 | vocabulary of coding so people can concentrate on what the programmer 1347 | is saying, rather than on how he/she is saying it. Global style rules are presented here so people know the vocabulary. However, 1348 | local style is also important. If the code added to a file 1349 | looks drastically different from the existing code around it, 1350 | the discontinuity throws readers out of their rhythm when they 1351 | go to read it. Try to avoid this. 1352 |
1353 | 1354 |1355 | OK, enough writing about writing code; the code itself is much 1356 | more interesting. Have fun! 1357 |
1358 | 1359 | 1360 |1362 | [1] Herb Sutter on software, hardware, and concurrency blog [http://herbsutter.com/2013/05/09/gotw-1-solution] 1363 |
1364 | 1365 | 1366 | 1367 | 1368 | -------------------------------------------------------------------------------- /settings-o2-codestyle-clion.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliceO2Group/CodingGuidelines/5c44b8bae3236da4dc8106dc2385825ddb112c4c/settings-o2-codestyle-clion.jar -------------------------------------------------------------------------------- /styleguide.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | color: #0e212e; 4 | font-family: sans-serif; 5 | font-size: 10pt; 6 | margin-right: 100px; 7 | margin-left: 100px; 8 | } 9 | 10 | a:link { 11 | color: #1f2669; 12 | } 13 | 14 | a:visited { 15 | color: #2b6790; 16 | } 17 | 18 | a:hover { 19 | color: #691f4b; 20 | } 21 | 22 | h1, h2, h3, h4, h5, h6, .toc_title { 23 | font-family: sans-serif; 24 | color: #1f4b69; 25 | margin-top: 2em; 26 | margin-bottom: 1em; 27 | } 28 | 29 | h1 { 30 | text-align: center; 31 | font-size: 18pt; 32 | } 33 | 34 | h2, .toc_title { 35 | font-weight: bold; 36 | font-size: 12pt; 37 | margin-left: -40px; 38 | } 39 | 40 | h3, h4, h5, h6 { 41 | font-size: 10pt; 42 | margin-left: -20px; 43 | } 44 | 45 | // clear floating boxes (C++11 box) on new stylepoints / categories 46 | h1, h2, h3 { 47 | clear: right; 48 | } 49 | 50 | .toc_category, .toc_stylepoint { 51 | font-family: sans-serif; 52 | font-size: 10pt; 53 | padding-top: .3em; 54 | padding-bottom: .3em; 55 | } 56 | 57 | table { 58 | border-collapse: collapse; 59 | } 60 | 61 | td, th { 62 | border: 1px solid #ccc; 63 | padding: 2px 12px; 64 | font-size: 10pt; 65 | } 66 | 67 | .toc td, .toc th { 68 | border-width: 1px 5px; 69 | } 70 | 71 | .todo_section { 72 | font-size: 150%; 73 | font-weight: bold; 74 | } 75 | 76 | code, samp, var { 77 | color: #2a6790; 78 | } 79 | 80 | div.cpp11box { 81 | float: right; 82 | clear: right; 83 | width: 50%; 84 | margin-right: -80px; 85 | margin-left: 1em; 86 | margin-top: 1ex; 87 | margin-bottom: 1ex; 88 | display: block; 89 | border-color: #1f4b69; 90 | border-style: solid; 91 | border-width: 1px; 92 | border-radius: 5px; 93 | -webkit-border-radius: 5px; 94 | -moz-border-radius: 5px; 95 | background-color: #dff3ff; 96 | padding: 0; 97 | } 98 | div.cpp11Header { 99 | background-color: #1f4b69; 100 | color: #dff3ff; 101 | text-align: right; 102 | margin: 0; 103 | padding-left: 0.5em; 104 | padding-right: 1.0em; 105 | padding-top: 2px; 106 | padding-bottom: 0; 107 | border-radius: 4px 4px 0 0; 108 | -webkit-border-radius: 4px 4px 0 0; 109 | -moz-border-radius: 4px 4px 0 0; 110 | } 111 | div.cpp11 { 112 | margin-left: 0.5em; 113 | margin-right: 0.5em; 114 | margin-top: 0.5ex; 115 | margin-bottom: 0.5em; 116 | padding: 0; 117 | } 118 | 119 | pre { 120 | white-space: pre-wrap; 121 | font-size: 10pt; 122 | display: block; 123 | color: #2a6790; 124 | background-color: #f8fff8; 125 | border-color: #f0fff0; 126 | border-style: solid; 127 | border-top-width: 1px; 128 | border-bottom-width: 1px; 129 | border-right-width: 1px; 130 | border-left-width: 5px; 131 | padding-left: 12px; 132 | padding-right: 12px; 133 | padding-top: 4px; 134 | padding-bottom: 4px; 135 | } 136 | 137 | pre.badcode { 138 | color: #c00; 139 | background-color: #fff8f8; 140 | border-color: #fff0f0; 141 | } 142 | 143 | .showhide_extrabutton, 144 | .showhide_button { 145 | float: left; 146 | cursor: pointer; 147 | border-width: 1px; 148 | border-style: solid; 149 | border-color: #ddd #aaa #aaa #ddd; 150 | padding: 0 3px 1px; 151 | margin: 0 4px 8px 0; 152 | border-radius: 3px; 153 | -webkit-border-radius: 3px; 154 | -moz-border-radius: 3px; 155 | } 156 | 157 | .link_button { 158 | float: left; 159 | display: none; 160 | background-color: #f8f8ff; 161 | border-color: #f0f0ff; 162 | border-style: solid; 163 | border-width: 1px; 164 | font-size: 75%; 165 | margin-top: 0; 166 | margin-left: -50px; 167 | padding: 4px; 168 | border-radius: 3px; 169 | -webkit-border-radius: 3px; 170 | -moz-border-radius: 3px; 171 | } 172 | 173 | .cpp11_marker { 174 | float: left; 175 | background-color: #1f4b69; 176 | border-color: #1f4b69; 177 | border-style: solid; 178 | border-width: 1px; 179 | color: #dff3ff; 180 | font-size: 75%; 181 | font-weight: bold; 182 | margin-top: 3ex; 183 | margin-right: 1em; 184 | margin-left: -100px; 185 | text-align: center; 186 | width: 40px; 187 | padding: 4px; 188 | border-radius: 1ex; 189 | -webkit-border-radius: 1ex; 190 | -moz-border-radius: 1ex; 191 | } 192 | 193 | address { 194 | text-align: right; 195 | } 196 | 197 | hr { 198 | margin-top: 3.5em; 199 | border-width: 1px; 200 | color: #fff; 201 | } 202 | 203 | .stylepoint_section { 204 | display: block; 205 | margin-bottom: 1em; 206 | color: #24597d; 207 | font-size: 90%; 208 | font-weight: bold; 209 | margin-left: -2%; 210 | } 211 | 212 | .stylepoint_subsection { 213 | color: #24597d; 214 | font-size: 90%; 215 | font-weight: bold; 216 | margin-left: -1%; 217 | } 218 | 219 | .stylepoint_subsubsection { 220 | color: #24597d; 221 | font-size: 80%; 222 | font-weight: bold; 223 | margin-left: 0; 224 | } 225 | 226 | .revision { 227 | text-align: right; 228 | } 229 | 230 | .comment_author { 231 | color: #3075A4; 232 | } 233 | 234 | .comment_barth { 235 | color: #660000; 236 | } 237 | 238 | @page { 239 | margin-left: 0; 240 | margin-right: 0; 241 | } 242 | @media print { 243 | body { 244 | font-size: 11pt; 245 | color: black; 246 | 247 | margin-left: 2cm; 248 | margin-right: 2cm; 249 | 250 | text-align: justify; 251 | } 252 | h2, .toc_title { 253 | margin-left: 0px; 254 | } 255 | h3, h4, h5, h6 { 256 | margin-left: 0px; 257 | } 258 | .stylepoint_section { 259 | margin-left: 0px; 260 | } 261 | .stylepoint_subsection { 262 | margin-left: 0px; 263 | } 264 | .cpp11_marker { 265 | margin-left: -17mm; 266 | margin-right: 0.5em; 267 | margin-top: 0; 268 | background: white; 269 | color: #1f4b69; 270 | } 271 | div.cpp11box { 272 | margin-right: -1cm; 273 | background: white; 274 | } 275 | div.cpp11Header { 276 | background: none; 277 | border-bottom: 1px solid #1f4b69; 278 | color: #1f4b69; 279 | } 280 | .showhide_button { 281 | display: none; 282 | } 283 | .link_button { 284 | display: none; 285 | visibility: hidden; 286 | } 287 | a { 288 | } 289 | a:link { 290 | text-decoration: none; 291 | color: black; 292 | } 293 | a:visited { 294 | text-decoration: none; 295 | color: black; 296 | } 297 | a:hover { 298 | text-decoration: none; 299 | color: black; 300 | } 301 | stylepoint_body { 302 | display: inline; 303 | } 304 | } 305 | --------------------------------------------------------------------------------