source: libcaca/trunk/doc/style.dox @ 3565

Last change on this file since 3565 was 3473, checked in by Sam Hocevar, 11 years ago

A lot of documentation updates here and there, including bugfixes dating
back to the libcucul merge.

  • Property svn:keywords set to Id
File size: 2.1 KB
RevLine 
[836]1/* $Id: style.dox 3473 2009-05-19 00:52:10Z sam $ */
2
[1879]3/** \page libcaca-style Libcaca coding style
[836]4
[844]5 \section sty1 General guidelines
[836]6
[844]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
28unsigned int x, y, w, h;
29char *font_name;
30void 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
40a += 2;
41b = (a * (c + d));
42x = min(x1, x2, x3);
43 \endcode
44
45 Do not put a space between functions and the corresponding opening
46 parenthesis:
47
48 \code
49int function(int);
[3473]50 \endcode
[844]51
[3473]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
[844]56if(a == b)
57    return;
[3473]58
59if (p == NULL)
[844]60 \endcode
61
62 Do not put parentheses around return values:
63
64 \code
65return 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
72int function(int a)
73{
74    if(a & 0x84)
[860]75        return a;
[844]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
[836]102*/
Note: See TracBrowser for help on using the repository browser.