[webkit-dev] unwritten rules of webkit style

Dirk Pranke dpranke at chromium.org
Thu Sep 3 00:18:06 PDT 2009


On Wed, Sep 2, 2009 at 8:43 PM, Ryan Leavengood<leavengood at gmail.com> wrote:
> 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.
>

I suppose it depends on your definitions, but the compiler would consider those
both single statements. That's the whole reason why the dangling else is evil.

-- Dirk

(Among the many WebKit rules that surprised me, I think this one surprised me
the most, but I'm not arguing that it should be changed at this point).


More information about the webkit-dev mailing list