Changes between Version 21 and Version 22 of CodingStyle
- Timestamp:
- Jan 18, 2010, 3:33:39 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CodingStyle
v21 v22 3 3 = BOINC coding style = 4 4 5 == All languages == 6 7 === Code factoring === 5 == All languages == #all-lang 6 7 === Code factoring === #factoring 8 8 9 9 * If code is repeated, factor it out and make it into a function. … … 12 12 * C++ `.h` files often contain both interface and implementation. Clearly divide these. 13 13 14 === Code documentation === 14 === Code documentation === #docs 15 15 16 16 * `.cpp` files have a comment at the top saying what's in the file (and perhaps what isn't). … … 18 18 * structs and classes are preceded by a comment saying what they are. 19 19 20 === Naming === 20 === Naming === #naming 21 21 22 22 * Names should be descriptive without being verbose (local variables names may be short). … … 25 25 * No mixed case names. 26 26 27 === Indentation === 27 === Indentation === #indent 28 28 29 29 * Each level of indentation is 4 spaces (not a tab). … … 47 47 }}} 48 48 49 === Constants === 49 === Constants === #constants 50 50 51 51 * There should be few numeric constants in code. Generally they should be `#define`s. 52 52 53 === Braces === 53 === Braces === #braces 54 54 55 55 * Opening curly brace goes at end of line (not next line): … … 74 74 75 75 76 === Comments and #ifdefs === 76 === Comments and #ifdefs === #comments 77 77 78 78 * Use `///` for all comments. The documentation is generated using Doxygen, so you should have a look at this example: … … 132 132 }}} 133 133 134 == C++ specific == 135 136 === Includes === 134 == C++ specific == #cpp 135 136 === Includes === #includes 137 137 138 138 * A `.cpp` file should have the minimum set of #includes to get that particular file to compile (e.g. the includes needed by {{{foo.cpp}}} should be in {{{foo.cpp}}}, not {{{foo.h}}}). 139 139 * Includes should be ordered from general (`<stdio.h>`) to specific (`thisfile.h`). 140 140 141 === Extern declarations === 141 === Extern declarations === #extern 142 142 143 143 * {{{foo.h}}} should have '{{{extern}}}' declarations for all public functions and variables in {{{foo.cpp}}} There should be no '{{{extern}}}' statements in {{{.cpp}}} files. 144 144 145 === Use of static === 145 === Use of static === #static 146 146 147 147 * If a function or variable is used in only one file, declare it {{{static}}}. 148 148 149 === Things to avoid unless there's a truly compelling reason: === 149 === Things to avoid unless there's a truly compelling reason: === #try-avoid 150 150 151 151 * Operator or function overloading. 152 152 * Templates. 153 153 154 === Things to avoid === 154 === Things to avoid === #avoid 155 155 156 156 * Use `typedef` (not `#define`) to define types. 157 157 * Don't use `memset()` or `memcpy()` to initialize or copy classes that are non-C compatible. Write a default constructor and a copy constructor instead. 158 158 159 === Error codes === 159 === Error codes === #error-codes 160 160 161 161 * (Almost) all functions should return an integer error code. Nonzero means error. See [source:trunk/boinc/lib/error_numbers.h lib/error_numbers.h] for a list of error codes. … … 166 166 }}} 167 167 168 === Structure definitions === 168 === Structure definitions === #structs 169 169 170 170 {{{ … … 178 178 }}} 179 179 180 == PHP specific == 181 182 === HTML === 180 == PHP specific == #php 181 182 === HTML === #html 183 183 184 184 PHP scripts should output "HTML 4.01 Transitional". … … 226 226 227 227 228 === Getting POST and GET data === 228 === Getting POST and GET data === #post-and-get 229 229 230 230 Do not access `$_POST` or `$_GET` directly. … … 232 232 These undo the effects of PHP magic quotes. 233 233 234 === Database access === 234 === Database access === #database-access 235 235 * Use the [PhpDb database abstraction layer]. 236 236 * If a POST or GET value will be used in a database query, use `BoincDb::escape_string` to escape it.