-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathHACKING
308 lines (223 loc) · 9.58 KB
/
HACKING
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
This file is about hacking beagle, the predecessor of beagrep, and
thus should be considered outdated.
Subversion
----------
Beagrep's source repository is in GNOME subversion, in the module 'beagrep'.
For information on GNOME svn, see:
http://developer.gnome.org/tools/svn.html.
Patches
-------
If you have a patch you'd like to submit, please open a tracking bug on
bugzilla.gnome.org (product 'beagrep'). Attach the patch (and any additional
required files) to the bug. The core developers are all on the beagrep-bugs
mailing list, so we'll see that it is there. We will review it, but if people
are busy it might not happen right away.
In the past we'd been doing patch review on the mailing list, but that hasn't
always worked very well. Sometimes patches get lost in the shuffle.
Organization
------------
Code that parses files or otherwise interacts w/ low-level details from
third-party apps (i.e. parsing gaim logs, undocumented nautilus metafiles and
stuff from .gnome2/epiphany, etc.) should probably be broken out into small
chunks of semi-independent code and placed in Beagrep/Util. That kind of code
is just ugly by nature, and I want to keep it from getting mixed into the
beagrep code as much as possible.
Anything in Util that requires gtk+ or gnome should be added to the UiUtil.dll
assembly. Otherwise, add it to the Util.dll assembly.
Coding Style
------------
Beagrep attempts to follow the Mono coding conventions. The following
description of those conventions was shamelessly stolen from Dashboard's
HACKING file.
* Tagging buggy code
If there is a bug in your implementation tag the problem by using
the word "FIXME" in the code, together with a description of the
problem.
Do not use XXX or TODO or obscure descriptions, because
otherwise people will not be able to understand what you mean.
* Basic code formatting
In order to keep the code consistent, please use the following
conventions. From here on `good' and `bad' are used to attribute
things that would make the coding style match, or not match. It is not
a judgement call on your coding abilities, but more of a style and
look call. Please follow these guidelines to ensure prettiness.
Use 8 space tabs for writing your code.
Since we are using 8-space tabs, you might want to consider the Linus
Torvalds trick to reduce code nesting. Many times in a loop, you will
find yourself doing a test, and if the test is true, you will
nest. Many times this can be changed. Example:
for (i = 0; i < 10; i++) {
if (Something (i)) {
DoMore ();
}
}
This take precious space, instead write it like this:
for (i = 0; i < 10; i++) {
if (! Something (i))
continue;
DoMore ();
}
A few guidelines:
* Use a space before an opening parenthesis when calling
functions, or indexing, like this:
Method (a);
b [10];
* Do not put a space after the opening parenthesis and the
closing one, ie:
good: Method (a); array [10];
bad: Method ( a ); array[ 10 ];
* Inside a code block, put the opening brace on the same line
as the statement:
good:
if (a) {
Code ();
Code ();
}
bad:
if (a)
{
Code ();
Code ();
}
* Avoid using unnecessary open/close braces, vertical space
is usually limited:
good:
if (a)
Code ();
bad:
if (a) {
Code ();
}
* However, when defining loops where the subpart could be
considered one statement, use open/close braces for
clarity. For example:
good:
while (true) {
if (a)
foo = true;
}
bad:
while (true)
if (a)
foo = true;
* When defining a method, use the C style for brace placement,
that means, use a new line for the brace, like this:
good:
void Method ()
{
}
bad:
void Method () {
}
* Properties and indexers are an exception, keep the
brace on the same line as the property declaration.
Rationale: this makes it visually
simple to distinguish them.
good:
int Property {
get {
return value;
}
}
bad:
int Property
{
get {
return value;
}
}
Notice how the accessor "get" also keeps its brace on the same
line.
For very small properties, you can compress things:
ok:
int Property {
get { return value; }
set { x = value; }
}
* Use white space in expressions liberally, except in the presence
of parenthesis:
good:
if (a + 5 > Method (Blah () + 4))
bad:
if (a+5>Method(Blah()+4))
* This also applies for "for" loops:
good:
for (int i = 0; i < 100; i++)
bad:
for (int i=0;i<100;i++)
* Please also use spaces and clear language (capitalization,
punctuation) in comments:
good:
// It's going to crash if we're not careful.
bad:
//its going to crash if were not careful
* For any new files, please use a descriptive introduction, like
this:
//
// System.Comment.cs: Handles comments in System files.
//
// Copyright (C) 2002 Address, Inc. (http://www.address.com)
//
* Also remember to include the license in comments at the top of
the file. Cut-and-paste this out of other source files in the
tree.
* Switch statements have the case at the same indentation as the
switch:
switch (x) {
case 'a':
...
case 'b':
...
}
* Large switch statements should have blank lines
between case statements:
switch (x) {
case 'a':
large code chunk;
case 'b':
another code chunk;
default:
another code chunk;
}
* All method names and properties should be StudlyCapped.
* Private variable members of a class and function
local variable names should be under_scored (no
camelCase please).
* C# is a pretty verbose and heavily-nested language. Don't
worry about trying to fit everything into 80 columns.
However, don't be afraid to use multiple lines, especially
with function arguments when it may be easier to read or
more aesthetic to do so.
If you are splitting a function declaration into multiple
lines, the arguments should be aligned to match the
opening brace:
void Function (int arg1, bool arg2,
bool arg3)
{
}
If you are splitting a function invokation, the overflowed
lines begin at the next tabbed position:
MyFunction ("Very long argument 1",
"Next argument begins at next tab",
"And so on");
* Best practices
* Use String.Empty instead of "" for any comparisons. This is
because using "" will cause a new string to be allocated,
whereas String.Empty is an interned reference.
* Instead of comparing strings against both null and "" or
String.Empty, use String.IsNullOrEmpty(). This function
was added in .NET 2.0, so large portions of the code
don't use this yet.
If you are using Emacs, you might want to put something like this
in your .emacs file:
(defun poor-mans-csharp-mode ()
(java-mode)
(setq mode-name "C#")
(set-variable 'tab-width 8)
(set-variable 'indent-tabs-mode t)
(set-variable 'c-basic-offset 8)
(c-set-offset 'inline-open 0)
(c-set-offset 'case-label 0)
)
(setq auto-mode-alist (append '(("\\.cs\\'" . poor-mans-csharp-mode))
auto-mode-alist))