Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/coding_standards.txt

Source at commit 335 created 13 years 9 months ago.
By azimutz, Ok, this were the fun stops :) - two keys to do the same thing, two keys to remember... thought it was a good idea to merge the best of the two, the educational side of arch=i386 + the practical one of -x32. And while i'm at it, why not make it even more practical!? Typing just 32 to get i386 arch. - -legacy kernel flag was not being passed on 10.6.x; the reason why is on the kernel code, Legacy mode is only available when i386 arch is specified (makes sense). So, while testing Meklort's kernel patcher, i felt the need to add the key. -legacy flag, sets i386 arch on the booter side & Legacy mode on the kernel side. - and how do we override the last two if they are flagged on Boot.plist? Typing just 64 to get x86_64 arch. - changed the code so x86_64 arch becomes default, seems more natural. And also added these flags to BootHelp.txt
1Coding Standard rev. 0 (First Draft)
2
31. Indentation
4 having seen most indentation styles going from 2 to 8 spaces, I would suggest a indentation of 4 spaces.
5
62. Comments
7I see here two main differents cases:
8function description comments and one-line code quite comments
9
10For functions documentation, I suggest to use this syntax
11/**
12 *
13 */
14Note the use of /** that will make future html auto-documentation easier (i.e: Doxygen at least recognize this marker)
15
16for punctual, short code comment, let's use:
17//
183) #define at top of document
194) Global vars right below #include / #define (notation: gLobal)
20Note that global vars and static vars should be avoided as much as possible in favor of local variables use, get/set functions (properties).
21
225) No curly brackets for single lines
23
246) else
25{
26 ....
27}
28
29instead of:
30
31else {
32 ....
33}
34
357) if
36{
37 ....
38}
39instead of:
40
41if {
42 ....
43}
44
458) fall through code (using indention) or bail out early (using returns)?
46Using early bail out for preconditions early in the function code,
47use common sense to avoid as an example more than 4 imbricated if() constructions.
48In the later case, consider decomposing your function in more manageable primitives.
49
509) Spaces/readability i.e. not: if (fd<0)
51but: if (fd < 0)
52
5310. types, variables, functions, naming
54non const variables should follow the (currently mostly used) CamelCase convention:
55int myVariableIsFine;
56instead of :
57int my_variable_is_ok;
58
59Functions should follow the same conventions except for standard c lib related functions.
60Types should share the same convention but start with a Captial letter instead of lower case.
61
6211. Please make sure you extensively initialize variables:
63avoid as much as possible:
64int myVar
65...
66myVar = 10;
67
68but use instead:
69int myVar = 10;
70
7112. const values:
72const int MY_CONST_VARIABLE=42; is also ok for me, depending on the context of use.
73or
74const int MyConstVariable = 42; (with a Capital first letter)
75
7613. macro definitions should follow this convention:
77#define MY_HANDY_MACROS_PSEUDO_FUNC() ...
78
7914. Macros use should be limited to really special cases where they bring real value (like special optimization cases)
80Most of the time inlining a function is much better than the use of macros
81
8215. Don't optimize your code blindly, always favor readability when in doubt.
83Very 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.
84

Archive Download this file

Revision: 335