NAME
|
style – Plan 9 coding conventions for C |
DESCRIPTION
|
Plan 9 C code has its own conventions. You would do well to follow
them. Here are a few: *don't use // comments; some old Plan 9 code does, but we're converting it as we touch it. We do sometimes use // to comment–out a few lines of code. *avoid gotos. *no tabs expanded to spaces. *surround a binary operator (particular a low precedence one) with spaces; don't try to write the most compact code possible but rather the most readable. *no white space before opening braces. *no white space after the keywords if, for, while, etc. *no braces around single–line blocks (e.g., if, for, and while bodies). *integer–valued functions return –1 on error, 0 or positive on success. *functions that return errors should set errstr(2). *variable and function names are all lowercase, with no underscores. *enum or #defined constants should be Uppercase (or UPPERCASE). *struct tags are Uppercase, with matching typedefs. *automatic variables (local variables inside a function) are never initialized at declaration. *follow the standard idioms: use x < 0 not 0 > x, etc. *don't write !strcmp (nor !memcmp, etc.); always explicitly compare the result of string comparison with zero using a relational operator. COMMENTS EFFICIENCY |
SEE ALSO
|
``Notes on Programming in C'', Rob Pike, http://www.literateprogramming.com/pikestyle.pdf |
BUGS
|
Some programs use very different styles, for example, rc.
|