Coding guidelines

Jeff Darcy jdarcy at redhat.com
Wed Jun 8 15:18:41 UTC 2011


I really hate having to deal with coding-style issues.  Generally I'll
accept anything that conforms to the Gluster [1] and/or Linux [2] coding
standards, and a whole lot that doesn't.  However, I do believe that
consistency with existing code is important, and some practices are
demonstrably bad for readability and maintainability [3].  So, here are
some rough guidelines.

* Tabs are eight spaces, and indents should be eight spaces as well.
Don't use indent=4 or pure spaces.

* Lines should *generally* be wrapped at 80 columns.  An occasional
hard-to-avoid long line is OK, but code with a high density of
> 80-column lines becomes unreadable.

* Don't do assignments within conditions.

* Don't rely on precedence of boolean/arithmetic/comparisons (pretty
much any binary operation besides selection).  Fully parenthesize nested
expressions involving these.

* Do put braces around if/else/for/while blocks, even if they only
contain a single statement.

* If you're going to use a goto-like flow of control for exception
handling, use a real goto.  Break statements in a "do ... while (0)" are
just label-less gotos, which is less readable and can cause unexpected
breakage if the form is nested.

I'm not going to demand that existing code be changed, and I'm generally
not going to clean them up myself (though I will be pushing a patch for
some of this in the uidmap code shortly), but as we move forward I'd
appreciate it if people could try to follow these guidelines.  Thanks.



[1]
http://download.gluster.com/pub/gluster/glusterfs/doc/coding-standard.pdf
[2] http://www.kernel.org/doc/Documentation/CodingStyle
[3] http://www.arrestedcomputing.com/pubs/readability-tse.pdf


More information about the cloudfs-devel mailing list