Trac is being migrated to new services! Issues can be found in our new
YouTrack instance and WIKI pages can be found on our
website.
- Timestamp:
-
Feb 28, 2014, 7:19:08 AM (10 years ago)
- Author:
-
MarkDoliner
- Comment:
-
Small improvements
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v6
|
v7
|
|
1 | | = Coding Standards = |
| 1 | = Code Style Guide = |
2 | 2 | |
3 | | We try to follow K&R coding style in most of our code. Some existing code violates these standards. If you are writing a patch against some such code, please do fix violations in that block of code – but don't reformat entire files! |
| 3 | Please follow these guidelines when writing new code in Pidgin, Finch, and libpurple. If you are writing a patch against code that violates these standards, please fix violations in that block of code – but don't reformat entire files! |
4 | 4 | |
5 | | Here are some examples to help explain the intended style: |
| 5 | In general we try to follow K&R coding style in most of our code. See below for specific examples: |
| 6 | |
6 | 7 | |
7 | 8 | == Braces == |
8 | | * Braces start at the same line as the if/while/do/for block |
9 | | * End braces are on their own lines, indented to the starting of the |
10 | | block, e.g.: |
| 9 | * Prefer braces around single line blocks. Reasons: |
| 10 | * Reduces chances of bugs, if someone adds code at the same indentation level without realizing that there are no braces. |
| 11 | * Smaller diffs when adding code to an existing single-line block. |
| 12 | * For functions, structs, typedefs, etc. braces start on their own lines. |
| 13 | * For if, while, do, for, etc. braces start on the same line. |
| 14 | * Braces end on their own lines, indented equally as the start of the |
| 15 | block. |
| 16 | |
11 | 17 | {{{ |
12 | 18 | #!c |
13 | | for (i = 0; i < x; i++) { |
14 | | /* the code here, indented by a tab */ |
15 | | } |
16 | | }}} |
17 | | * The starting braces for functions, structs etc. are on their own lines e.g.: |
18 | | {{{ |
19 | | #!c |
20 | | struct _somestruct |
| 19 | static void |
| 20 | some_function(int x, int y) |
21 | 21 | { |
22 | | /* stuff */ |
| 22 | if (x > y) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | for (i = 0; i < x; i++) { |
| 27 | /* the code here, indented by a tab */ |
| 28 | } |
23 | 29 | }; |
24 | 30 | }}} |
25 | 31 | |
| 32 | |
26 | 33 | == Indentation == |
27 | | * We use tab for indentation (and it's preferable that you use 8-space tabs in your editor) |
| 34 | * We use tab for indentation (and it's preferable that you use 8-space tabs in your editor). |
| 35 | * When wrapping long lines, tab indent to the start of the statement then add two more tabs. |
28 | 36 | |
29 | 37 | |
… |
… |
|
38 | 46 | }}} |
39 | 47 | * No whitespace at the end of line |
| 48 | |
40 | 49 | |
41 | 50 | == Comments == |
… |
… |
|
55 | 64 | }}} |
56 | 65 | |
| 66 | |
57 | 67 | == Function Definitions == |
58 | | |
59 | 68 | * There should be a newline between the return type of the function and the function's name. |
60 | 69 | * Wrap parameters sensibly, preferably around 80 characters or so. |
… |
… |
|
70 | 79 | /* misc, other */ |
71 | 80 | } |
| 81 | |
| 82 | |
| 83 | == Variable Declarations == |
| 84 | * Prefer declaring each variable on its own line. This makes diffs easier to read and reduces churn. |
| 85 | * Use const for variables that don't need to change or be deallocated. |
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!