Chameleon

Chameleon Commit Details

Date:2010-01-17 13:53:49 (4 years 9 months ago)
Author:JrCs
Commit:13
Parents: 12
Message:Added a first draft for the coding standards, please help to get it more complete (while keeping it simple enough to be appplied) and consistent.
Changes:
A/branches/JrCs/coding_standards.txt

File differences

branches/JrCs/coding_standards.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Coding Standard rev. 0 (First Draft)
1. Indentation
having seen most indentation styles going from 2 to 8 spaces, I would suggest a indentation of 4 spaces.
2. Comments
I see here two main differents cases:
function description comments and one-line code quite comments
For functions documentation, I suggest to use this syntax
/**
*
*/
Note the use of /** that will make future html auto-documentation easier (i.e: Doxygen at least recognize this marker)
for punctual, short code comment, let's use:
//
3) #define at top of document
4) Global vars right below #include / #define (notation: gLobal)
Note that global vars and static vars should be avoided as much as possible in favor of local variables use, get/set functions (properties).
5) No curly brackets for single lines
6) else
{
....
}
instead of:
else {
....
}
7) if
{
....
}
instead of:
if {
....
}
8) fall through code (using indention) or bail out early (using returns)?
Using early bail out for preconditions early in the function code,
use common sense to avoid as an example more than 4 imbricated if() constructions.
In the later case, consider decomposing your function in more manageable primitives.
9) Spaces/readability i.e. not: if (fd<0)
but: if (fd < 0)
10. types, variables, functions, naming
non const variables should follow the (currently mostly used) following convention:
int myVariableIsFine;
instead of :
int my_variable_is_ok;
Functions should follow the same conventions except for standard c lib related functions.
Types should share the same convention but start with a Captial letter instead of lower case.
11. Please make sure you extensively initialize variables:
avoid as much as possible:
int myVar
...
myVar = 10;
but use instead:
int myVar = 10;
12. const values:
const int MY_CONST_VARIABLE=42; is also ok for me, depending on the context of use.
or
const int MyConstVariable = 42; (with a Capital first letter)
13. macro definitions should follow this convention:
#define MY_HANDY_MACROS_PSEUDO_FUNC() ...
14. Macros use should be limited to really special cases where they bring real value (like special optimization cases)
Most of the time inlining a function is much better than the use of macros
15. Don't optimize your code blindly, always favor readability when in doubt.
Very often, optimization is not necessary where you think it is, think about the bubble sort algorithm, where people would code it in assembly, where a heap or quick sort algorithm would be much more efficient (n log(n) instead of quadratic complexity), as an example when values count to be sorted get high.

Archive Download the corresponding diff file

Revision: 13