Skip to contentSkip to conversation

Coding style and standardisation

RFC In review Mark Williamson 2 participants 2 messages Jun 4, 2007

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Coding style and standardisation

Hi all,

The coding style in the Xen tree is somewhat varied these days - there are a few deviations from the "standard" that have crept in over time. I've been trying to think of ways we can help contributors understand how the code is supposed to look in a canonical form, rather than people trying to judge from code already there.

Attached is a little extra documentation - my quick stab at summing up the Xen coding style. I think the main points of difference from the Linux coding style are summarised here, but if anybody has anything else they think should be included (or anything they disagree with in my summary) it would be handy to know.

I've also attached a modified-for-Xen version of a (the?) Linux patch style checker. It might not be 100% accurate, but it should give folks a pretty good idea of any obvious style changes they need to make.

My hope is that this will reduce review burden (for reviewers and submitters) and eventually get the codebase back towards a uniform coding style. This is a component of my exploration of automated code quality checking for the Xen codebase.

Comments, anyone?

Cheers,
Mark

Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat?  And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!

# HG changeset patch
# User [email protected]
# Date 1180932960 -3600
# Node ID 19dea8353434ba799f5b7e46e1d6ffdf2943a74c
# Parent bd3d6b4c52ec809f080c89c4ffcf61dc6e445978 Basic Xen CodingStyle guide, plus automated patch style checker.

docs/misc/CodingStyle new file +77 -0
diff -r bd3d6b4c52ec -r 19dea8353434 docs/misc/CodingStyle
@@ -0,0 +1,77 @@
+Coding Style for the Xen Hypervisor
+===================================
+
+This coding style is used for C code that is part of the Xen
+Hypervisor itself, or part of the associated user space tools.  Guest
+operating system code may use the native coding style of that
+code base.  The goal of this file is to document the main points of the
+Xen coding style, particularly where they differ from normal Linux
+convention.
+
+Indentation
+-----------
+
+Indenting uses spaces, not tabs - in contrast to Linux.  An indent
+level consists of four spaces.  Code within blocks is indented by one
+extra indent level.  The enclosing braces of a block are indented the
+same as the code _outside_ the block.  E.g.
+
+void fun(void)
+{
+    /* One level of indent. */
+
+    {
+        /* A second level of indent. */
+    }
+}
+
+White space
+-----------
+
+Space characters are used to spread out logical statements, such as in
+the condition of an if or while.  Spaces are placed between the
+keyword and the brackets surrounding the condition, between the
+brackets and the condition itself, and surrounding brackets and
+operators within the expression itself.  E.g.
+
+if ( ( wibble & wombat ) == 42 )
+{
+    ...
+
+Bracing
+-------
+
+Braces ('{' and '}') are always placed on a line of their own.  This
+is unlike the Linux coding style and unlike K&R.  E.g.:
+
+if ( condition )
+{
+    /* Do stuff. */
+}
+
+while ( condition )
+{
+    /* Do stuff. */
+}
+
+etc.
+
+Comments
+--------
+
+Only C style /* ... */ comments are to be used.  C++ style // comments
+should not be used in submitted code.  Multi-word comments should
+begin with a capital letter and end with a full stop.
+
+Style checking
+--------------
+
+Automated style checking for patches to the Xen code base is provided
+by tools/misc/xenstylecheck.pl .  This tool will attempt to spot
+common style problems.  If it complains at you, it doesn't necessarily
+mean you need to change your code but you should understand why you're
+not following the style.  xenstylecheck.pl is derived closely from
+patchstyleemailcheck.pl by Dave Jones and Joel Scohpp.  Bug reports,
+queries and suggestions regarding this derivative should be addressed
+to Mark Williamson <[email protected]> or
[email protected] and not to the original authors.
tools/misc/xenstylecheck.pl new file +215 -0

215 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 5 lines · Mark Williamson

Attached is a little extra documentation - my quick stab at summing up the Xen coding style. I think the main points of difference from the Linux coding style are summarised here, but if anybody has anything else they think should be included (or anything they disagree with in my summary) it would be handy to know.

White space: only put spaces inside outermost brackets of if/while/for. For example, "if ( (wibble & wombat) == 42 )".

Comments:
/*
* Multi-line comments are formatted like this.
* No trailing white space, even at the end of the first line. */

Top-of-file comments: see e.g., common/page_alloc.c for preferred style.

Emacs style: it's okay to put an Emacs style block at the end of files, e.g., as in common/page_alloc.c.

-- Keir