1 | /* $Id: style.dox 3473 2009-05-19 00:52:10Z sam $ */ |
---|
2 | |
---|
3 | /** \page libcaca-style Libcaca coding style |
---|
4 | |
---|
5 | \section sty1 General guidelines |
---|
6 | |
---|
7 | A pretty safe rule of thumb is: look at what has already been done and |
---|
8 | try to do the same. |
---|
9 | |
---|
10 | - Tabulations should be avoided and replaced with \e eight spaces. |
---|
11 | - Indentation is generally 4 spaces. |
---|
12 | - Lines should wrap at most at 79 characters. |
---|
13 | - Do not leave whitespace at the end of lines. |
---|
14 | - Do not use multiple spaces for anything else than indentation. |
---|
15 | - Code qui fait des warnings == code de porc == deux baffes dans ta gueule |
---|
16 | |
---|
17 | \section sty2 C coding style |
---|
18 | |
---|
19 | Try to use short names whenever possible (\c i for indices, \c w for width, |
---|
20 | \c cv for canvas...). Macros are always uppercase, variable and function |
---|
21 | names are always lowercase. Use the underscore to separate words within |
---|
22 | names: |
---|
23 | |
---|
24 | \code |
---|
25 | #define BROKEN 0 |
---|
26 | #define MAX(x, y) ((x > y) ? (x) : (y)) |
---|
27 | |
---|
28 | unsigned int x, y, w, h; |
---|
29 | char *font_name; |
---|
30 | void frobulate_every_three_seconds(void); |
---|
31 | \endcode |
---|
32 | |
---|
33 | \c const is a \e suffix. It's \c char \c const \c *foo, not \c const \c char |
---|
34 | \c *foo. |
---|
35 | |
---|
36 | Use spaces after commas and between operators. Do not use spaces after an |
---|
37 | opening parenthesis or before a closing one: |
---|
38 | |
---|
39 | \code |
---|
40 | a += 2; |
---|
41 | b = (a * (c + d)); |
---|
42 | x = min(x1, x2, x3); |
---|
43 | \endcode |
---|
44 | |
---|
45 | Do not put a space between functions and the corresponding opening |
---|
46 | parenthesis: |
---|
47 | |
---|
48 | \code |
---|
49 | int function(int); |
---|
50 | \endcode |
---|
51 | |
---|
52 | A space can be inserted after keywords such as \c for, \c while or \c if, |
---|
53 | but consistency with the rest of the page is encouraged: |
---|
54 | |
---|
55 | \code |
---|
56 | if(a == b) |
---|
57 | return; |
---|
58 | |
---|
59 | if (p == NULL) |
---|
60 | \endcode |
---|
61 | |
---|
62 | Do not put parentheses around return values: |
---|
63 | |
---|
64 | \code |
---|
65 | return a + (b & x) + d[10]; |
---|
66 | \endcode |
---|
67 | |
---|
68 | Opening braces should be on a line of their own, aligned with the |
---|
69 | current block. Braces are optional for one-liners: |
---|
70 | |
---|
71 | \code |
---|
72 | int function(int a) |
---|
73 | { |
---|
74 | if(a & 0x84) |
---|
75 | return a; |
---|
76 | |
---|
77 | if(a < 0) |
---|
78 | { |
---|
79 | return -a; |
---|
80 | } |
---|
81 | else |
---|
82 | { |
---|
83 | a /= 2; |
---|
84 | |
---|
85 | switch(a) |
---|
86 | { |
---|
87 | case 0: |
---|
88 | case 1: |
---|
89 | return -1; |
---|
90 | break; |
---|
91 | default: |
---|
92 | return a; |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | \endcode |
---|
97 | |
---|
98 | \section sty3 C++ coding style |
---|
99 | |
---|
100 | Nothing here yet. |
---|
101 | |
---|
102 | */ |
---|