1 This document defines many guidelines that should be adhered to when developing
2 against Banshee. These guidelines will make the codebase more readable,
3 extensible, and portable.
5 Commit Message Guidelines
6 =========================
8 Every change to source code must have a commit message associated to it. The
9 formatting details of this message are described here:
11 http://live.gnome.org/Git/CommitMessages
13 Please review these guidelines separate to this document.
16 C# Coding Style Guidelines
17 ==========================
19 These guidelines should be followed when writing code in Banshee. For the most
20 part they are similar to the Mono syntax guidelines [1]. All public API must
21 adhere to the .NET Framework Design Guidelines. [2]
23 Patches and additions to the code base will be checked for adherence to these
24 guidelines. If code is in violation, you will be asked to reformat it.
26 1. Private variable/field names should be written like:
28 lower_case_with_under_scores
30 2. Property, event, and method names should be written like:
32 UpperCaseStartingLetter
34 3. A space before method/conditional parenthesis, braces:
37 CallSomeFunction (args);
40 4. One space before a brace on the same line as a conditional or property:
46 5. Namespace, Class, Method braces on separate lines:
52 private void Method ()
61 6. The exception to rule 5 is for Properties. The brace in the same line
62 with the get/set keyword and the respective getter/setter block all
63 inline, provided the block is simple:
65 public string Something {
69 7. If the property accessor block (get/set) is more than one line, use the
72 public string Something {
79 8. There is a space between generic parameters:
81 Dictionary<K, V> not Dictionary<K,V>
83 9. Use 4 space characters for indention, NOT tabs
85 10. Try to observe a 120 character wrap margin. If your lines are over 120
86 characters, break and indent them logically.
89 .NET API Naming Guidelines
90 ==========================
92 1. Member names should be descriptive and it is best to avoid abbreviations
95 2. If an abbreviation or acronym is used, it should be in the form of an
96 accepted name that is generally well known
98 3. If an acronym is one-two characters long, it should be all caps
100 Banshee.IO and not Banshee.Io
102 4. If an acronym is three or more characters long, only its first letter
103 should be capitalized
106 Banshee.Playlists.Formats.Pls
107 Banshee.Playlists.Formats.M3u
109 5. Prefix interfaces with 'I'
115 Implementation Guidelines
116 =========================
118 1. Use generics and generic collections when possible in place of
119 1.0 features. New code in Banshee should leverage 2.0 features
120 as much as possible, and old code should be updated as development
121 occurs in a given area.
123 Use List<T> instead of ArrayList, Dictionary<K, V> instead of Hashtable
125 2. In *most* cases Banshee.IO should be used (and possibly extended) when
126 IO must be performed. Do *NOT* hard-code System.IO, Mono.Unix, or
127 Gnome.Vfs IO into top-level APIs.
129 3. When a platform-specific task needs to be performed, a top-level,
130 generic API must be designed first and then the platform implementation
131 of the API can be added. See Banshee.Configuration for ideas.
133 4. Do not hard code path separators. Use Path.DirectorySeparatorChar instead
134 as it is portable to other platforms.
136 5. Try not to perform many string concatenations. Use a StringBuilder if
139 6. Avoid calls to Assembly.GetTypes as memory resulting from these calls
143 Organization Guidelines
144 =======================
146 1. Organize code into logical namespaces:
150 Banshee.Cdrom.Nautilus
152 2. Try to keep GUI as separate as possible from "real work" and keep
153 the namespace separate as well, if possible and applicable. For instance,
154 Many different CD-ROM backends could be written for different
155 platforms, but the same GUI should be used. Don't put GUI code in
156 the platform implementation:
160 Banshee.Cdrom.Nautilus
162 3. Banshee's sources are layed out in the following way in the build:
164 src/<high-level-group>/<assembly-name>/<namespace>/<class-or-interface>.cs
166 4. Small member definitions (delegates, argument classes, enums) can go
167 inside the same file containing the primary class, but classes should
168 generally be in separate files. Use logical grouping with files.
171 [1] http://www.mono-project.com/Coding_Guidelines
172 [2] Highly recommended reading: http://www.amazon.com/gp/product/0321246756/ or
173 view at: http://msdn2.microsoft.com/en-us/library/ms229042.aspx