[bind10-dev] [bikeshed] C++ indentation style

Stephen Morris stephen at isc.org
Fri Feb 4 12:45:55 UTC 2011


On 03/02/2011 19:47, JINMEI Tatuya / 神明達哉 wrote:
> I've noticed that recent BIND 10 C++ code has a mixture of two
> different indentation styles for multi-line expressions:
> (traditional?) BSD style and BSD KNF style and  (see
> http://en.wikipedia.org/wiki/Indent_style).
> 
> 1. In the (traditional?) BSD style, continuing lines are aligned with
>    the corresponding opening parenthesis:
> 
>     if (JS_DefineProperty(cx, o, "data",
>                           STRING_TO_JSVAL(JS_NewStringCopyN(cx, data, res)),
>                           NULL, NULL, JSPROP_ENUMERATE) != 0) {
> 
> 2. In the KNF style, continuing lines always start at the same column,
>    indented by the size of "soft tab":
> 
>     if (JS_DefineProperty(cx, o, "data",
>         STRING_TO_JSVAL(JS_NewStringCopyN(cx, data, res)),
>         NULL, NULL, JSPROP_ENUMERATE) != 0) {
> 
> I'd like to keep the style consistent (I have my own preference, which
> is style #1, but I don't mind using a non preferred style if that's
> the group consensus).
> 
> Both styles have pros and cons:
>  - style #1 is (at least seemingly) consistent with other ISC code
>    including BIND 9 and DHCP.
>  - style #1 better clarifies the relationship between a function and
>    its parameters (it's clearer in style #1 that NULLs are parameters
>    of JS_DefineProperty(), not STRING_TO_JSVAL()).
>  - style #2 uses the space more efficiently (style #1 tends to require
>    large redundant spaces in the left side, which can lead to
>    unnecessarily longer lines)
>  - (very minor point) style #1 is more friendly with Emacs (as far as
>    I know we need to write a custom hook to use style #2 on Emacs)
>  - (ditto) style #2 is (reportedly?) more friendly with vi
>    
> But I think this is largely a preference matter in the end, and using
> consistent style is much more important to me (the mixture of these
> styles is reducing code readability pretty substantially).
> 
> If there is the majority that prefers a particular style, I'm okay
> with adopting it.  If there's no clear majority, I propose using style
> #1 because of its consistency with other ISC code (disclaimer: I may
> be biased here because #1 is my preferred style).
> 
> Does this proposal make sense?  If so, which style do main developers
> prefer?

I prefer the second; if you have several multi-line function calls one
after the other, I think it looks untidy to use varying indentations.

But I have no fixed preferences - I will go with whatever is deemed the
standards.

Stephen



More information about the bind10-dev mailing list