comparison doc/HACKING @ 4778:dde7262d0a35

Moved HACKING and TODO under doc/.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 22 Sep 2008 20:14:12 +0300
parents HACKING@c1c536313023
children
comparison
equal deleted inserted replaced
4777:1f03f17e263e 4778:dde7262d0a35
1 Hacking / coding guide for Audacious and Audacious-plugins
2 ==========================================================
3 (C) Copyright 2008 Audacious Development Team
4
5
6 Preamble
7 ========
8
9 This document describes the guidelines for people who wish to work on
10 improving or cleaning up Audacious media player, or any of the plugins
11 we distribute in the plugins package.
12
13 It is probably obvious to anyone who has taken a look into the depths
14 of Audacious source, that many of these guidelines are not actually
15 followed currently in all places, if at all.
16
17 In fact, the purpose of this document is to act as a target to aim at,
18 when noticing and cleaning up uncompliant code.. or writing new code.
19
20
21 Coding guidelines
22 =================
23 - Public functions in Audacious core SHOULD be documented via Doxygen
24 comments! In this case "public" means any functions that span modules
25 OR are available to plugins.
26
27 Of course, most functions currently lack documentation. If you have
28 spare time, improve the situation.
29
30
31 - We use Glib for portability. This means that we have sized integer types
32 such as gint{16,32,64}, etc. and shorthand types like guint and guchar
33 provided, so please do use them.
34
35 Arguably C99 provides inttypes.h with similar types, but C99 support
36 may not be complete on all platforms, it is both safer and more uniform
37 to use glib types.
38
39
40 - Use other glib functionality, especially string handling like:
41 * g_snprintf(), g_strdup_printf(), g_strdup() ...
42
43
44 - However, avoid following Glib things:
45 * GString - Useless in most cases compared to normal 'C' string functions
46 and introduces conversions back and forth.
47
48 * GList - GList is slow, either use GQueue or libmowgli lists.
49
50
51 - Be sure to know when you are handling UTF-8 or something else! Glib offers
52 special g_ascii_*() functions for certain operations that you might need
53 when handling non-unicode strings.
54
55
56 - When reading data from files, it's usually a BIG mistake to read structs
57 directly from the stream! This is not portable, as C does not guarantee
58 a struct not to have alignment padding (unless the struct is "packed",
59 but see below.) In effect sizeof(struct), unless packed, on some platform
60 may not be equal to some other platform.
61
62 Making struct "packed" via the C packed qualifier or "#pragma pack()" is
63 a solution, but this must be used with care. Unaligned memory access
64 causes performance penalties, and may cause other, more serious problems
65 in some cases. For example, code written in assembler may not know about
66 the un-alignment, and may thus fail with 'bus errors' on platforms that
67 strictly required aligned data.
68
69 The 100% safe way is to read individual members of the struct one by one
70 from the stream. This may be bothersome, but by doing so, your code
71 will be portable for sure.
72
73
74 - Always use Glib sized types for reading integer data from file streams.
75 Using plain C types (like 'long int' for example) is not wise, because
76 they may be of different size on different platforms depending on the
77 platform ABI. For example, on some 64-bit platforms, 'long int' is
78 64 bits, while on 32-bit platforms it is 32 bits.
79
80
81 - Audacious core provides some helper functions for reading endian-dependant
82 integers from VFS streams (aud_vfs_fget_{le,be}{16,32,64}), see vfs.h and
83 documentation for more information.
84
85
86 - Avoid reinventing wheels, avoid code duplication. If same thing is done
87 in two places, it should be in a library, or possibly in Audacious core.
88 Discuss about it with fellow developers.
89
90
91 - In the core, DO NOT WRITE CODE THAT IS DEPENDENT ON A SPECIFIC UI OR
92 INTERFACE. The core should NEVER care what interface is in use.
93
94
95 Additional style guidelines
96 ===========================
97
98 - Indentation: Use the same indentation style (also spaces vs. tabs)
99 as the file you are editing. In new files/code, use indentation of
100 4 spaces (no tabs). When moving functions to new files, PLEASE
101 reindent the code.
102
103 - Whitespace usage in code:
104
105 a = 1;
106
107 if (b == d && !strcmp(a, c)) ...
108
109 - Blocks:
110
111 while (...)
112 {
113 do_something(...);
114 }
115
116 if (...)
117 {
118 do_stuff();
119 }
120 else
121 {
122 do_other_stuff();
123 }