Mercurial > audlegacy
annotate HACKING @ 4417:f922499e69bc
Fix typos, etc.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Mon, 31 Mar 2008 09:32:45 -0500 |
parents | 2c3390afe10e |
children | 7df56e5ec76b |
rev | line source |
---|---|
4415
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 Hacking / coding guide for Audacious and Audacious-plugins |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 ========================================================== |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 (C) Copyright 2008 Audacious Development Team |
4417 | 4 Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org>, and mercilessly |
5 edited by others. | |
4415
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 |
4417 | 8 Preamble |
9 ======== | |
10 | |
4415
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 This document describes the guidelines for people who wish to work on |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 improving or cleaning up Audacious media player, or any of the plugins |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 we distribute in the plugins package. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 It is probably obvious to anyone who has taken a look into the depths |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 of Audacious source, that many of these guidelines are not actually |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 followed currently in all places, if at all. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 In fact, the purpose of this document is to act as a target to aim at, |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 when noticing and cleaning up uncompliant code.. or writing new code. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 Coding guidelines |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 ================= |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 - We use Glib for portability. This means that we have sized integer types |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 like gint{16,32,64}, etc. and shorthand types like guint and guchar |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 provided, so please do use them. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 Arguably C99 provides inttypes.h with similar types, but C99 support |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 may not be complete on all platforms, it is both safer and more uniform |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 to use glib types. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 - Use other glib functionality, especially string handling like: |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 * g_snprintf(), g_strdup_printf(), g_strdup() ... |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 - However, avoid following Glib things: |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 * GString - Useless in most cases compared to normal 'C' string functions |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 and introduces conversions back and forth. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 * GList - GList is slow, either use GQueue or libmowgli lists. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 - Be sure to know when you are handling UTF-8 or something else! Glib offers |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 special g_ascii_*() functions for certain operations that you might need |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 when handling non-unicode strings. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 - When reading data from files, it's usually a BIG mistake to read structs |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 directly from the stream! This is not portable, as C does not guarantee |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 a struct not to have alignment padding (unless the struct is "packed", |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 but see below.) In effect sizeof(struct) on some platform may not be |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 equal to some other platform. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 Some clever people might think that making struct "packed" via the |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 C packed qualifier would be a solution, but this will |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 What you SHOULD do is read individual members of the struct one by one |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 from the stream. This may sound bothersome, but by doing so, your code |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 will be portable. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 - Always use Glib sized types for reading integer data from file streams. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 Using plain C types (like 'long int' for example) is not wise, because |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 they may be of different size on different platforms depending on the |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 platform ABI. For example, on some 64-bit platforms, 'long int' is |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 64 bits, while on 32-bit platforms it is 32 bits. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 - Audacious core provides some helper functions for reading endian-dependant |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 integers from VFS streams (aud_vfs_fget_{le,be}{16,32,64}), see vfs.h and |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 documentation for more information. |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 Additional style guidelines |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 =========================== |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 - Indentation: Use the same indentation style (also spaces vs. tabs) |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 as the file you are editing. In new files/code, use indentation of |
4417 | 83 4 spaces (no tabs). When moving functions to new files, PLEASE |
84 reindent the code. | |
4415
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 - Whitespace usage in code: |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 a = 1; |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 if (b == d && !strcmp(a, c)) ... |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 - Blocks: |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
4417 | 94 while (...) |
95 { | |
96 do_something(...); | |
4415
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 } |
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 |
4417 | 99 if (...) |
100 { | |
101 do_stuff(); | |
4415
2c3390afe10e
Added a coding guideline document.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 } |
4417 | 103 else |
104 { | |
105 do_other_stuff(); | |
106 } |