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

Jelte Jansen jelte at isc.org
Tue Feb 15 10:12:07 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/15/2011 09:21 AM, JINMEI Tatuya / 神明達哉 wrote:
>     if (JS_DefineProperty(cx, o, "data", STRING_TO_JSVAL(
>                               JS_NewStringCopyN(cx, data, res)),
>                           NULL, NULL, JSPROP_ENUMERATE) != 0) {
>     }

hmm, this is also a combination, and tbh one that I would not use myself.

Let me add some more colors to the bikeshed mix and take this example, with a
slight modification (i'm gonna make the argument names to JS_NewStringCopyN a
bit longer, to trigger more long line problems), and show the results of a few
possible indentation schemes.

(the mailer probably breaks this down though, so lines starting at the first
column should be read as though continuing on the previous line. Probably
proving some points here :))

with the above indentation it would look like this

    if (JS_DefineProperty(cx, o, "data", STRING_TO_JSVAL(
                              JS_NewStringCopyN(some_context,
source_data_buffer, result_data_buffer)),
                          NULL, NULL, JSPROP_ENUMERATE) != 0) {
    }


with indentation strictly to opening braces, you'd get:

    if (JS_DefineProperty(cx, o, "data",
                          STRING_TO_JSVAL(JS_NewStringCopyN(some_context,
                                                            source_data_buffer,
                                                            result_data_buffer)),
                          NULL, NULL, JSPROP_ENUMERATE) != 0) {
    }

(lots of wasted whitespace, and result_data_buffer exceeds the limit here)

with a strict 'one tab per level' kind of indentation, you'd get this:

    if (JS_DefineProperty(cx, o, "data",
        STRING_TO_JSVAL(JS_NewStringCopyN(some_context,
            source_data_buffer, result_data_buffer)),
        NULL, NULL, JSPROP_ENUMERATE) != 0) {
    }

this is the most concise, however, IMO it's not directly clear where the
arguments belong (since "if (" happens to be exactly four characters, one might
at very first glance not realize STRING_TO_JSVAL() and the next NULL are
arguments to JS_DefineProperty)

The one i was talking about looks like this:

    if (JS_DefineProperty(cx, o, "data",
           STRING_TO_JSVAL(JS_NewStringCopyN(some_context,
                              source_data_buffer, result_data_buffer)),
           NULL, NULL, JSPROP_ENUMERATE) != 0) {
    }

Instead of a strict tab, use a reference point in the previous line (or rather,
the function we are indenting an argument for), in this case the first
underscore (or capital in case of CamelCasing). This is less strict, but I think
allows for more lenience to make it 'look good'.

There are of course endless numbers of combinations, and YMMV, and no scheme
will never run into spacing issues, especially with long names and namespaces
etc. :)

Jelte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1aUXcACgkQ4nZCKsdOncWboACaA6s7RNPplQ48o8GSHdPisAEC
e4UAn1cjCgrRWdTA3fzU/YJT9P0FsbFB
=vWNU
-----END PGP SIGNATURE-----



More information about the bind10-dev mailing list