Changes between Version 30 and Version 31 of CodingStyle
- Timestamp:
- Jun 18, 2018, 5:59:46 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CodingStyle
v30 v31 12 12 * C++ `.h` files often contain both interface and implementation. Clearly divide these. 13 13 14 === Error codes === #error-codes 15 16 * (Almost) all functions should return an integer error code. 17 Nonzero means error. See [source:boinc/lib/error_numbers.h lib/error_numbers.h] for a list of error codes. 18 The only exception to this is PHP database access functions, which use the mysql_* convention 19 that zero means error, and you call mysql_error() or mysql_error_string() to find details. 20 * Calls to functions that return an error code should check the code. 21 Generally they should return non-zero on error, e.g.: 22 {{{ 23 retval = blah(); 24 if (retval) return retval; 25 }}} 26 14 27 === Code documentation === #docs 15 28 16 * `.cpp`files have a comment at the top saying what's in the file (and perhaps what isn't).29 * All files have a comment at the top saying what's in the file (and perhaps what isn't). 17 30 * Functions are preceded by a comment saying what they do. 18 31 * structs and classes are preceded by a comment saying what they are. … … 51 64 * There should be few numeric constants in code. Generally they should be `#define`s. 52 65 53 === Braces === #braces66 === Braces (C++ and PHP) === #braces 54 67 55 68 * Opening curly brace goes at end of line (not next line): … … 73 86 }}} 74 87 75 76 88 === Comments and #ifdefs === #comments 77 89 78 * Use `//` for all comments.79 * Comment out blocks of code as follows:90 * For C++ and PHP, use `//` for all comments. 91 * End multi-line comments with an empty comment line, e.g. 80 92 {{{ 81 #if 0 82 ... 83 #endif 93 // This function does blah blah 94 // Call it when blah blah 95 // 96 function foo() { 97 } 84 98 }}} 85 99 … … 114 128 * Dynamic memory allocation. Functions shouldn't return pointers to malloc'd items. 115 129 116 === Error codes === #error-codes117 130 118 * (Almost) all functions should return an integer error code.119 Nonzero means error. See [source:boinc/lib/error_numbers.h lib/error_numbers.h] for a list of error codes.120 * Calls to functions that return an error code should check the code.121 Generally they should return non-zero on error, e.g.:122 {{{123 retval = blah();124 if (retval) return retval;125 }}}126 131 127 132 === Structure definitions === #structs … … 137 142 }}} 138 143 144 === Comments === 145 Comment out blocks of code as follows: 146 {{{ 147 #if 0 148 ... 149 #endif 150 }}} 139 151 == PHP specific == #php 140 152