comparison HACKING @ 4415:2c3390afe10e

Added a coding guideline document.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 31 Mar 2008 17:21:21 +0300
parents
children ac8d871b6075 f922499e69bc
comparison
equal deleted inserted replaced
4414:2592487d149c 4415:2c3390afe10e
1 Hacking / coding guide for Audacious and Audacious-plugins
2 ==========================================================
3 (C) Copyright 2008 Audacious Development Team
4 Written by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
5
6
7 Premeable
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
24 - We use Glib for portability. This means that we have sized integer types
25 like gint{16,32,64}, etc. and shorthand types like guint and guchar
26 provided, so please do use them.
27
28 Arguably C99 provides inttypes.h with similar types, but C99 support
29 may not be complete on all platforms, it is both safer and more uniform
30 to use glib types.
31
32
33 - Use other glib functionality, especially string handling like:
34 * g_snprintf(), g_strdup_printf(), g_strdup() ...
35
36
37 - However, avoid following Glib things:
38 * GString - Useless in most cases compared to normal 'C' string functions
39 and introduces conversions back and forth.
40
41 * GList - GList is slow, either use GQueue or libmowgli lists.
42
43
44 - Be sure to know when you are handling UTF-8 or something else! Glib offers
45 special g_ascii_*() functions for certain operations that you might need
46 when handling non-unicode strings.
47
48
49 - When reading data from files, it's usually a BIG mistake to read structs
50 directly from the stream! This is not portable, as C does not guarantee
51 a struct not to have alignment padding (unless the struct is "packed",
52 but see below.) In effect sizeof(struct) on some platform may not be
53 equal to some other platform.
54
55 Some clever people might think that making struct "packed" via the
56 C packed qualifier would be a solution, but this will
57
58 What you SHOULD do is read individual members of the struct one by one
59 from the stream. This may sound bothersome, but by doing so, your code
60 will be portable.
61
62
63 - Always use Glib sized types for reading integer data from file streams.
64 Using plain C types (like 'long int' for example) is not wise, because
65 they may be of different size on different platforms depending on the
66 platform ABI. For example, on some 64-bit platforms, 'long int' is
67 64 bits, while on 32-bit platforms it is 32 bits.
68
69
70 - Audacious core provides some helper functions for reading endian-dependant
71 integers from VFS streams (aud_vfs_fget_{le,be}{16,32,64}), see vfs.h and
72 documentation for more information.
73
74
75
76 Additional style guidelines
77 ===========================
78
79 - Indentation: Use the same indentation style (also spaces vs. tabs)
80 as the file you are editing. In new files/code, use indentation of
81 4 spaces (no tabs).
82
83 - Whitespace usage in code:
84
85 a = 1;
86
87 if (b == d && !strcmp(a, c)) ...
88
89 - Blocks:
90
91 while (...) {
92 do_something(...)
93 }
94
95 if (...) {
96 } else {
97 }