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
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
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
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
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
64 A good way to let new contributors know how to contribute :)
\r
66 CODING_STYLE | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
67 1 files changed, 291 insertions(+), 0 deletions(-)
\r
68 create mode 100644 CODING_STYLE
\r
70 diff --git a/CODING_STYLE b/CODING_STYLE
\r
71 new file mode 100644
\r
72 index 0000000..95ceac0
\r
76 +Cairo coding style.
\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
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
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
97 +Each new level is indented 4 more spaces than the previous level:
\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
108 +The tab character must always be interpreted according to its
\r
109 +traditional meaning:
\r
111 + Advance to the next column which is a multiple of 8.
\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
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
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
132 +Most of the code in cairo uses bracing in the style of K&R:
\r
141 +but some of the code uses an alternate style:
\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
157 +If all of the substatements of an if statement are single statements,
\r
158 +the optional braces should not usually appear:
\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
171 + } else /* Yuck! */
\r
174 +And of course, there are exceptions for when the code just looks
\r
175 +better with the braces:
\r
178 + /* Note that we have to be careful here. */
\r
179 + do_something_dangerous (with_care);
\r
183 + other_condition &&
\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
193 + other_condition &&
\r
194 + yet_another) { /* Yuck! */
\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
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
208 + struct _cairo_gstate {
\r
209 + cairo_operator_t op;
\r
211 + double tolerance;
\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
219 + cairo_fill_rule_t fill_rule;
\r
223 + double dash_offset;
\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
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
235 + if (condition) foo (); else bar (); /* Yuck! */
\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
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
245 + chmod a+x .git/hooks/pre-commit
\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
251 +As a special case of the bracing and whitespace guidelines, function
\r
252 +definitions should always take the following form:
\r
255 + my_function (argument)
\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
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
268 + align_function_arguments (argument_the_first,
\r
269 + argument_the_second,
\r
270 + argument_the_third);
\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
277 + align_parameter_names_in_prototypes (const char *char_star_arg,
\r
279 + double *double_star_arg,
\r
280 + double double_arg);
\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
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
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
296 + foo = malloc (sizeof (foo_t));
\r
297 + if (foo) { /* Yuck! */
\r
299 + /* lots of code to initialize foo */
\r
305 +This kind of gratuitous nesting can be avoided by following a pattern
\r
306 +of handling exceptional cases early and returning:
\r
308 + foo = malloc (sizeof (foo_t));
\r
313 + /* lots of code to initialize foo */
\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
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
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
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
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
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
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
354 +As a reward for reading this far, here are some mode lines for the more
\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
365 +Write rules for common editors to use this style. Also cleanup/unify
\r
366 +the modelines in the source files.
\r