Changes between Version 10 and Version 11 of CodingRules
- Timestamp:
- 11/26/13 15:40:33 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CodingRules
v10 v11 5 5 0. Declare variables as late as possible. To understand code, it makes sense to have all you need as close as possible which avoids scrolling forth and back. 6 6 0. The indentation is 4. No tabs allowed. 7 0. Curly braces are *always* on a single empty line (this gives a clear structure to the code), although in *switch* statements. 7 0. Curly braces are *always* on a single empty line (this gives a clear structure to the code), although in *switch* statements. No comments on the line with the opening brace. Put them above (e.g. the if-clause) or below in the next line. 8 8 0. *goto* is a no-go, it breaks the structure of the code (check google for details) 9 9 0. In switch statements the *case* label is on the same level as the *switch*. The corresponding code or brackets are indented. … … 35 35 0. Try to avoid using dynamic allocation whenever possible: "int i=5; /* do something with i*/; /* i runs out of scope */" is preferred over "int *i = new int; *i=5; /* do something with i */; delete i;" Although this example sounds ridiculous, the same is true for every class instance you allocate. 36 36 0. Initialization of all data members using their constructor (see example) is preferred over using assignments (optimization reasons) 37 0. Keep your code linear! Avoid using a lot of if-else and blocks in loops. Use *continue* and *break* instead (easier to read, human brains have difficulties to handle to many levels, better fits on the screen, easier to optimize) 37 38 39 40 Exception from these rules are of course acceptable but should stay an exception. Exceptions are only useful if using a different style, 41 reveals the structure of the code (what the code is doing) much better. 38 42 == Example == 39 43 {{{#!C++