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

Kenneth Christiansen kenneth.christiansen at openbossa.org
Thu Dec 3 05:01:11 PST 2009


Nice, that change would make it compatible with the Qt style guide! I:-) I
say go for it!

Kenneth

On Thu, Dec 3, 2009 at 2:00 AM, Peter Kasting <pkasting at google.com> wrote:

> 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) {
>   a;
>   b;
>   c;
>   // etc., very long body
> } else
>   x;
>
> ...or perhaps:
>
> if (foo)
>   a;
> else if (bar) {
>   b;
>   c;
> } else if (baz)
>   d;
> else if (qux) {
>   e;
>   f;
> }
>
> 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.)
>
> PK
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>
>


-- 
Kenneth Rohde Christiansen
Technical Lead / Senior Software Engineer
Qt Labs Americas, Nokia Technology Institute, INdT
Phone  +55 81 8895 6002 / E-mail kenneth.christiansen at openbossa.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20091203/585b01df/attachment.html>


More information about the webkit-dev mailing list