[webkit-dev] Proposing style guide change regarding braces on conditional arms

Peter Kasting pkasting at google.com
Wed Dec 2 21:00:59 PST 2009

This is a followup to my thread yesterday regarding consistent enforcement
of the style guide.  Like Yong Li, I find the current rule about braces on
conditional arms to be suboptimal.  The current rule is that one-line arms
must not have braces.  This leads to strange constructions like:

if (foo) {
  // etc., very long body
} else

...or perhaps:

if (foo)
else if (bar) {
} else if (baz)
else if (qux) {

I find this tricky to read and error-prone.  I propose that the rule be
modified to be:

* When all arms of a conditional or loop are one physical line, do not use
braces.  If any arms are more than one physical line (even if they are one
logical line), use braces on all arms.

In most places this will not differ from the existing code, so it will not
"cause the whole codebase to become invalid"; but it prevents cases where
the inconsistency leads (IMO) to lower readability/safety.  (As a bonus for
Chromium developers, it's compatible with the Google style guide too,
although it goes further than that guide in order to make the correct style
explicit in all cases.)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20091202/1eab3acd/attachment-0001.html>

More information about the webkit-dev mailing list