Re: [PATCH] emacs: do not change users' mail agent configuration
[notmuch-archives.git] / 6f / 4034dc2bdf6f126f29eeffd4339627fde9817f
1 Return-Path: <polatel@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 69D3A431FBC\r
6         for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 05:40:53 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.046\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.046 tagged_above=-999 required=5 tests=[AWL=-0.574,\r
12         BAYES_50=0.001, RCVD_IN_SORBS_WEB=0.619] autolearn=no\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 6Gn52KVE5+IO for <notmuch@notmuchmail.org>;\r
16         Wed, 13 Jan 2010 05:40:52 -0800 (PST)\r
17 Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com\r
18         [209.85.218.224])\r
19         by olra.theworths.org (Postfix) with ESMTP id 5B57B431FAE\r
20         for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 05:40:52 -0800 (PST)\r
21 Received: by bwz24 with SMTP id 24so15214459bwz.30\r
22         for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 05:40:51 -0800 (PST)\r
23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
24         h=domainkey-signature:received:received:sender:from:to:subject:date\r
25         :message-id:x-mailer:organization;\r
26         bh=rtPfbUZNu2K1RvXWAn89qEvCJAiYRaQrzc2HJAY3Kgw=;\r
27         b=Q1p/WzyXpqW6hSCUUbA4RhE4HtV8l6au2hmPbtU07JXhtN0IpOpwhkOQ16rosLAEGR\r
28         UCcggM1+Lk2x7atnGE5ZFAUqFthiA85vY4q9vD2EXrX8QYyOPuG+UdTlFxIiw05flKHf\r
29         BFUDkpi//qP07Cez9rPGNXw+yBueMlRF1XrZU=\r
30 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
31         h=sender:from:to:subject:date:message-id:x-mailer:organization;\r
32         b=fEvuFDF4WDHNnGZArhIP4ZPnN/QM9WQeoMtywvtScCtgzOtO3gA+GDN2N7PjDCymup\r
33         NTiI43utgLmiiqlaL67N111ySJrs1Y1Op9KWggsVNOt7N/205qZIi+gdBySwc1yhqAmm\r
34         NR05v43IvuW3zXeBtC3pMbqIcPvqDJj/mo12Q=\r
35 Received: by 10.204.27.16 with SMTP id g16mr2569252bkc.97.1263390051237;\r
36         Wed, 13 Jan 2010 05:40:51 -0800 (PST)\r
37 Received: from harikalardiyari ([78.179.54.193])\r
38         by mx.google.com with ESMTPS id 14sm3618297bwz.1.2010.01.13.05.40.49\r
39         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
40         Wed, 13 Jan 2010 05:40:50 -0800 (PST)\r
41 Sender: Ali Polatel <polatel@gmail.com>\r
42 From: Ali Polatel <alip@exherbo.org>\r
43 To: notmuch@notmuchmail.org\r
44 Date: Wed, 13 Jan 2010 15:40:42 +0200\r
45 Message-Id:\r
46  <24296f98dcf960342b02d2e1bbb303fd0ad4fa67.1263389936.git.alip@exherbo.org>\r
47 X-Mailer: git-send-email 1.6.6\r
48 Organization: Pink Floyd\r
49 Subject: [notmuch] [PATCH] Import CODING_STYLE from cairo\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Wed, 13 Jan 2010 13:40:53 -0000\r
63 \r
64 A good way to let new contributors know how to contribute :)\r
65 ---\r
66  CODING_STYLE |  291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
67  1 files changed, 291 insertions(+), 0 deletions(-)\r
68  create mode 100644 CODING_STYLE\r
69 \r
70 diff --git a/CODING_STYLE b/CODING_STYLE\r
71 new file mode 100644\r
72 index 0000000..95ceac0\r
73 --- /dev/null\r
74 +++ b/CODING_STYLE\r
75 @@ -0,0 +1,291 @@\r
76 +Cairo coding style.\r
77 +\r
78 +This document is intended to be a short description of the preferred\r
79 +coding style for the cairo source code. Good style requires good\r
80 +taste, which means this can't all be reduced to automated rules, and\r
81 +there are exceptions.\r
82 +\r
83 +We want the code to be easy to understand and maintain, and consistent\r
84 +style plays an important part in that, even if some of the specific\r
85 +details seem trivial. If nothing else, this document gives a place to\r
86 +put consistent answers for issues that would otherwise be arbitrary.\r
87 +\r
88 +Most of the guidelines here are demonstrated by examples, (which means\r
89 +this document is quicker to read than it might appear given its\r
90 +length). Most of the examples are positive examples that you should\r
91 +imitate. The few negative examples are clearly marked with a comment\r
92 +of /* Yuck! */. Please don't submit code to cairo that looks like any\r
93 +of these.\r
94 +\r
95 +Indentation\r
96 +-----------\r
97 +Each new level is indented 4 more spaces than the previous level:\r
98 +\r
99 +       if (condition)\r
100 +           do_something ();\r
101 +\r
102 +This may be achieved with space characters or a combination of tab\r
103 +characters and space characters. It may not be achieved with tab\r
104 +characters exclusively (see below).\r
105 +\r
106 +Tab characters\r
107 +--------------\r
108 +The tab character must always be interpreted according to its\r
109 +traditional meaning:\r
110 +\r
111 +       Advance to the next column which is a multiple of 8.\r
112 +\r
113 +With this definition, even levels of indentation can be achieved with\r
114 +a sequence of tab characters, while odd levels of indentation may\r
115 +begin with a sequence of tab character but must end with 4 space\r
116 +characters.\r
117 +\r
118 +Some programmers have been misled by certain text editors into\r
119 +thinking that 4-space indentation can be achieved with tab characters\r
120 +exclusively by changing the meaning of tab character to be "advance to\r
121 +the next column which is a multiple of 4". Code formatted in this way,\r
122 +making an assumption of a fictitious 4-character-tab will not be\r
123 +accepted into cairo.\r
124 +\r
125 +The rationale here is that tabs are used in the code for lining things\r
126 +up other than indentation, (see the Whitespace section below), and\r
127 +changing the interpretation of tab from its traditional meaning will\r
128 +break this alignment.\r
129 +\r
130 +Braces\r
131 +------\r
132 +Most of the code in cairo uses bracing in the style of K&R:\r
133 +\r
134 +       if (condition) {\r
135 +           do_this ();\r
136 +           do_that ();\r
137 +       } else {\r
138 +           do_the_other ();\r
139 +       }\r
140 +\r
141 +but some of the code uses an alternate style:\r
142 +\r
143 +       if (condition)\r
144 +       {\r
145 +           do_this ();\r
146 +           do_that ();\r
147 +       }\r
148 +       else\r
149 +       {\r
150 +           do_the_other ();\r
151 +       }\r
152 +\r
153 +and that seems just fine. We won't lay down any strict rule on this\r
154 +point, (though there should be some local consistency). If you came\r
155 +here hoping to find some guidance, then use the first form above.\r
156 +\r
157 +If all of the substatements of an if statement are single statements,\r
158 +the optional braces should not usually appear:\r
159 +\r
160 +       if (condition)\r
161 +           do_this ();\r
162 +       else\r
163 +           do_that ();\r
164 +\r
165 +But the braces are mandatory when mixing single statement and compound\r
166 +statements in the various clauses. For example, do not do this:\r
167 +\r
168 +       if (condition) {\r
169 +           do_this ();\r
170 +           do_that ();\r
171 +       } else                  /* Yuck! */\r
172 +           do_the_other ();\r
173 +\r
174 +And of course, there are exceptions for when the code just looks\r
175 +better with the braces:\r
176 +\r
177 +       if (condition) {\r
178 +           /* Note that we have to be careful here. */\r
179 +           do_something_dangerous (with_care);\r
180 +       }\r
181 +\r
182 +       if (condition &&\r
183 +           other_condition &&\r
184 +           yet_another)\r
185 +       {\r
186 +           do_something ();\r
187 +       }\r
188 +\r
189 +And note that this last example also shows a situation in which the\r
190 +opening brace really needs to be on its own line. The following looks awful:\r
191 +\r
192 +       if (condition &&\r
193 +           other_condition &&\r
194 +           yet_another) {      /* Yuck! */\r
195 +           do_something ();\r
196 +       }\r
197 +\r
198 +As we said above, legible code that is easy to understand and maintain\r
199 +is the goal, not adherence to strict rules.\r
200 +\r
201 +Whitespace\r
202 +----------\r
203 +Separate logically distinct chunks with a single newline. This\r
204 +obviously applies between functions, but also applies within a\r
205 +function or block and can even be used to good effect within a\r
206 +structure definition:\r
207 +\r
208 +       struct _cairo_gstate {\r
209 +           cairo_operator_t op;\r
210 +\r
211 +           double tolerance;\r
212 +\r
213 +           /* stroke style */\r
214 +           double line_width;\r
215 +           cairo_line_cap_t line_cap;\r
216 +           cairo_line_join_t line_join;\r
217 +           double miter_limit;\r
218 +\r
219 +           cairo_fill_rule_t fill_rule;\r
220 +\r
221 +           double *dash;\r
222 +           int num_dashes;\r
223 +           double dash_offset;\r
224 +\r
225 +           ...\r
226 +       }\r
227 +\r
228 +Use a single space before a left parenthesis, except where the\r
229 +standard will not allow it, (eg. when defining a parameterized macro).\r
230 +\r
231 +Don't eliminate newlines just because things would still fit on one\r
232 +line. This breaks the expected visual structure of the code making it\r
233 +much harder to read and understand:\r
234 +\r
235 +       if (condition) foo (); else bar ();     /* Yuck! */\r
236 +\r
237 +Do eliminate trailing whitespace (space or tab characters) on any\r
238 +line. Also, avoid putting initial or final blank lines into any file,\r
239 +and never use multiple blank lines instead of a single blank line.\r
240 +\r
241 +Do enable the default git pre-commit hook that detect trailing\r
242 +whitespace for you and help you to avoid corrupting cairo's tree with\r
243 +it. Do that as follows:\r
244 +\r
245 +       chmod a+x .git/hooks/pre-commit\r
246 +\r
247 +You might also find the git-stripspace utility helpful which acts as a\r
248 +filter to remove trailing whitespace as well as initial, final, and\r
249 +duplicate blank lines.\r
250 +\r
251 +As a special case of the bracing and whitespace guidelines, function\r
252 +definitions should always take the following form:\r
253 +\r
254 +       void\r
255 +       my_function (argument)\r
256 +       {\r
257 +           do_my_things ();\r
258 +       }\r
259 +\r
260 +And function prototypes should similarly have the return type (and\r
261 +associated specifiers and qualifiers) on a line above the function, so\r
262 +that the function name is flush left.\r
263 +\r
264 +Break up long lines (> ~80 characters) and use whitespace to align\r
265 +things nicely. For example the arguments in a long list to a function\r
266 +call should all be aligned with each other:\r
267 +\r
268 +       align_function_arguments (argument_the_first,\r
269 +                                 argument_the_second,\r
270 +                                 argument_the_third);\r
271 +\r
272 +And as a special rule, in a function prototype, (as well as in the\r
273 +definition), whitespace should be inserted between the parameter types\r
274 +and names so that the names are aligned:\r
275 +\r
276 +       void\r
277 +       align_parameter_names_in_prototypes (const char *char_star_arg,\r
278 +                                            int         int_arg,\r
279 +                                            double     *double_star_arg,\r
280 +                                            double      double_arg);\r
281 +\r
282 +Note that parameters with a * prefix are aligned one character to the\r
283 +left so that the actual names are aligned.\r
284 +\r
285 +Managing nested blocks\r
286 +----------------------\r
287 +Long blocks that are deeply nested make the code very hard to\r
288 +read. Fortunately such blocks often indicate logically distinct chunks\r
289 +of functionality that are begging to be split into their own\r
290 +functions. Please listen to the blocks when they beg.\r
291 +\r
292 +In other cases, gratuitous nesting comes about because the primary\r
293 +functionality gets buried in a nested block rather than living at the\r
294 +primary level where it belongs. Consider the following:\r
295 +\r
296 +       foo = malloc (sizeof (foo_t));\r
297 +       if (foo) {                                      /* Yuck! */\r
298 +           ...\r
299 +           /* lots of code to initialize foo */\r
300 +           ...\r
301 +           return SUCCESS;\r
302 +       }\r
303 +       return FAILURE;\r
304 +\r
305 +This kind of gratuitous nesting can be avoided by following a pattern\r
306 +of handling exceptional cases early and returning:\r
307 +\r
308 +       foo = malloc (sizeof (foo_t));\r
309 +       if (foo == NULL)\r
310 +           return FAILURE;\r
311 +\r
312 +       ...\r
313 +       /* lots of code to initialize foo */\r
314 +       ...\r
315 +       return SUCCESS;\r
316 +\r
317 +The return statement is often the best thing to use in a pattern like\r
318 +this. If it's not available due to additional nesting above which\r
319 +require some cleanup after the current block, then consider splitting\r
320 +the current block into a new function before using goto.\r
321 +\r
322 +Memory allocation\r
323 +-----------------\r
324 +\r
325 +Because much of cairo's data consists of dynamically allocated arrays,\r
326 +it's very easy to introduce integer overflow issues whenever malloc()\r
327 +is called.  Use the _cairo_malloc2(), _cairo_malloc3(), and\r
328 +_cairo_malloc2_add1 macros to avoid these cases; these macros check\r
329 +for overflow and will return NULL in that case.\r
330 +\r
331 +  malloc (n * size) => _cairo_malloc_ab (n, size)\r
332 +    e.g. malloc (num_elts * sizeof(some_type)) =>\r
333 +         _cairo_malloc2 (num_elts, sizeof(some_type))\r
334 +\r
335 +  malloc (a * b * size) => _cairo_malloc_abc (a, b, size)\r
336 +    e.g. malloc (width * height * 4) =>\r
337 +         _cairo_malloc3 (width, height, 4)\r
338 +\r
339 +  malloc (n * size + k) => _cairo_malloc_ab_plus_c (n, size, k)\r
340 +    e.g. malloc (num * sizeof(entry) + sizeof(header)) =>\r
341 +         _cairo_malloc2k (num, sizeof(entry), sizeof(header))\r
342 +\r
343 +In general, be wary of performing any arithmetic operations in an\r
344 +argument to malloc.  You should explicitly check for integer overflow\r
345 +yourself in any more complex situations.\r
346 +\r
347 +Mode lines\r
348 +----------\r
349 +\r
350 +So given the rules above, what is the best way to simplify one's life as\r
351 +a code monkey? Get your editor to do most of the tedious work of\r
352 +beautifying your code!\r
353 +\r
354 +As a reward for reading this far, here are some mode lines for the more\r
355 +popular editors:\r
356 +/*\r
357 + * vim:sw=4:sts=4:ts=8:tw=78:fo=tcroq:cindent:cino=\:0,(0\r
358 + * vim:isk=a-z,A-Z,48-57,_,.,-,>\r
359 + */\r
360 +\r
361 +\r
362 +TODO\r
363 +----\r
364 +\r
365 +Write rules for common editors to use this style.  Also cleanup/unify\r
366 +the modelines in the source files.\r
367 -- \r
368 1.6.6\r
369 \r