[webkit-dev] unwritten rules of webkit style

Ryan Leavengood leavengood at gmail.com
Wed Sep 2 20:43:33 PDT 2009


On Wed, Sep 2, 2009 at 11:15 PM, TAMURA, Kent<tkent at chromium.org> wrote:
>
> A few days ago, this rule brought a real bug to me.
> Existing code:
>   if (attr->name() == fooAttr)
>       doSometing();
>   else if (attr->name() == barAttr) ...
> I added "if" like:
>   if (attr->name() == fooAttr)
>       if (isBaz())
>           doSometing();
>   else if (attr->name() == barAttr) ...
> The "else" clause unexpectedly attached to "if (isBaz())"
> I wasted about an hour to found this bug.

Yes that's annoying, but the moment you added that second if the first
if was no longer a single statement.

Having braces all the time would avoid such bugs, but frankly this is
a pretty basic aspect of C and C++ that a developer should learn about
pretty early. I don't think it is worth cluttering up the code with
unneeded braces just to avoid these occasional bugs.

Either way you probably won't make this mistake again. That's how we
all learned, the hard way :)

-- 
Regards,
Ryan


More information about the webkit-dev mailing list