3 style \- Plan 9 coding conventions for C
5 Plan 9 C code has its own conventions.
6 You would do well to follow them.
11 comments; some old Plan 9 code does, but we're converting it as we touch it.
14 to comment-out a few lines of code.
19 no tabs expanded to spaces.
21 surround a binary operator (particular a low precedence one) with spaces;
22 don't try to write the most compact code possible
23 but rather the most readable.
25 parenthesize expressions involving arithmetic and bit-wise operators;
26 otherwise don't parenthesize heavily (e.g., as in Pascal).
28 no white space before opening braces.
30 no white space after the keywords
36 no braces around single-line blocks (e.g.,
43 integer-valued functions return -1 on error, 0 or positive on success.
45 functions that return errors should set
48 variable and function names are all lowercase, with no underscores.
53 constants should be Uppercase (or UPPERCASE).
56 tags are Uppercase, with matching
59 automatic variables (local variables inside a function) are
60 never initialized at declaration.
62 follow the standard idioms: use
74 .LR "if(memcmp(a, b, c))" ;
75 always explicitly compare the result of string or memory
76 comparison with zero using a relational operator.
78 Ultimately, the goal is to write code that fits in with the other code
79 around it and the system as a whole. If the file you are editing
80 already deviates from these guidelines, do what it does. After you
81 edit a file, a reader should not be able to tell just from coding
82 style which parts you worked on.
84 If your code is readable, you shouldn't need many comments. A line or
85 two comment above a function explaining what it does is always welcome.
87 Comment any code you find yourself wondering about for more than 2
88 seconds, even if it's to say that you don't understand what's going
91 Don't use commenting as an excuse for writing confusing code. Rewrite
92 the code to make it clear.
94 Do the simple thing. Don't optimize unless you've measured the code
95 and it is too slow. Fix the data structures and the algorithms
96 instead of going for little 5% tunings.
98 ``Notes on Programming in C'', Rob Pike,
100 .B http://www.literateprogramming.com/pikestyle.pdf
102 Some programs use very different styles, for example,
105 Some programs and programmers diverge from the above rules due to
106 habits formed long before these rules.
107 Notably, some programs have a single space after a keyword and
108 before an opening brace,
109 and some initialize automatic variables at declaration.