On Wed, Sep 2, 2009 at 11:15 PM, TAMURA, Kent<tk...@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 _______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev