summaryrefslogtreecommitdiff
path: root/HACKING
blob: 9313b351308e3ef1e920440562e0f99ae5ff876e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
This document defines many guidelines that should be adhered to when developing 
against Banshee. These guidelines will make the codebase more readable,
extensible, and portable.

Commit Message Guidelines
=========================

Every change to source code must have a commit message associated to it. The
formatting details of this message are described here:

  http://live.gnome.org/Git/CommitMessages

Please review these guidelines separate to this document.


C# Coding Style Guidelines
==========================

These guidelines should be followed when writing code in Banshee. For the most
part they are similar to the Mono syntax guidelines [1]. All public API must
adhere to the .NET Framework Design Guidelines. [2]

Patches and additions to the code base will be checked for adherence to these
guidelines. If code is in violation, you will be asked to reformat it.

  1. Private variable/field names should be written like:

      lower_case_with_under_scores

  2. Property, event, and method names should be written like:

      UpperCaseStartingLetter

  3. A space before method/conditional parenthesis, braces:

      if (condition) {
         CallSomeFunction (args);
      }

  4. One space before a brace on the same line as a conditional or property:

      while (condition) {
         ...
      }

  5. Namespace, Class, Method braces on separate lines:

      namespace Foo
      {
          public class Bar
          {
              private void Method ()
              {
                  if (condition) {
                      ..
                  }
              }
          }
      }

  6. The exception to rule 5 is for Properties. The brace in the same line
     with the get/set keyword and the respective getter/setter block all
     inline, provided the block is simple:

      public string Something {
          get { return "yay"; }
      }

  7. If the property accessor block (get/set) is more than one line, use the
     alternative syntax:
     
      public string Something {
          set {
              DoSomething ();
              something = value;
          }
      }

  8. There is a space between generic parameters:

      Dictionary<K, V> not Dictionary<K,V>

  9. Use 4 space characters for indentation, NOT tabs (except in Makefiles)
   
  10. Try to observe a 120 character wrap margin. If your lines are over 120
     characters, break and indent them logically.

  11. One space at both sides of all type of operators (assignment,
     equality, mathematical, event-subscription, ...):

      var compare = (a + b * c) != (d - e * f);


.NET API Naming Guidelines
==========================

  1. Member names should be descriptive and it is best to avoid abbreviations
     and acronyms

  2. If an abbreviation or acronym is used, it should be in the form of an 
     accepted name that is generally well known

  3. If an acronym is one-two characters long, it should be all caps 

      Banshee.IO and not Banshee.Io

  4. If an acronym is three or more characters long, only its first letter
     should be capitalized

      Banshee.Cdrom
      Banshee.Playlists.Formats.Pls
      Banshee.Playlists.Formats.M3u

  5. Prefix interfaces with 'I'

      IPlaylist
      IImportable


Implementation Guidelines
=========================

  1. Use generics and generic collections when possible in place of 
     1.0 features. New code in Banshee should leverage 2.0 features 
     as much as possible, and old code should be updated as development
     occurs in a given area.

      Use List<T> instead of ArrayList, Dictionary<K, V> instead of Hashtable

  2. In *most* cases Banshee.IO should be used (and possibly extended) when
     IO must be performed. Do *NOT* hard-code System.IO, Mono.Unix, or
     Gnome.Vfs IO into top-level APIs.

  3. When a platform-specific task needs to be performed, a top-level, 
     generic API must be designed first and then the platform implementation
     of the API can be added. See Banshee.Configuration for ideas.
   
  4. Do not hard code path separators. Use Path.DirectorySeparatorChar instead
     as it is portable to other platforms. 

  5. Try not to perform many string concatenations. Use a StringBuilder if
     necessary
   
  6. Avoid calls to Assembly.GetTypes as memory resulting from these calls
     will not be GCed.


Organization Guidelines
=======================

  1. Organize code into logical namespaces:

      Banshee.Cdrom
      Banshee.Cdrom.Gui
      Banshee.Cdrom.Nautilus

  2. Try to keep GUI as separate as possible from "real work" and keep
     the namespace separate as well, if possible and applicable. For instance,
     Many different CD-ROM backends could be written for different 
     platforms, but the same GUI should be used. Don't put GUI code in
     the platform implementation:

      Banshee.Cdrom
      Banshee.Cdrom.Gui
      Banshee.Cdrom.Nautilus

  3. Banshee's sources are layed out in the following way in the build:

     src/<high-level-group>/<assembly-name>/<namespace>/<class-or-interface>.cs

  4. Small member definitions (delegates, argument classes, enums) can go
     inside the same file containing the primary class, but classes should
     generally be in separate files. Use logical grouping with files.


[1] http://www.mono-project.com/Coding_Guidelines
[2] Highly recommended reading: http://www.amazon.com/gp/product/0321246756/ or
    view at: http://msdn2.microsoft.com/en-us/library/ms229042.aspx