On Tue, May 26, 2009 at 6:22 PM, Aaron Boodman <a...@chromium.org> wrote:
>
> I get different stories about this all the time from different people.
> It would be great to have them as part of the style guide so that I
> can refer to it.
>
> One that you didn't cover is the invariant case. I originally used
> DCHECKs, but it seems like if you're just going to crash on the next
> line anyway, a CHECK makes more sense.

Here's what I do:

Generally, use DCHECK().

Use CHECK when the problem indicates a potential security problem.
I've also added them in cases where there are crash reports and I
can't find the source of the problem. CHECK()s around the entrypoints
for various conditions can help narrow this down.

Don't bother doing an assertion when the next line will crash anyway:
  DCHECK(foo);
  foo->DoSomething();
will normally crash pretty obviously dereferencing a NULL pointer
(even though it will be inside DoSomething). NULL pointer dereferences
are usually the easiest bugs to see. DCHECK in this situation is
especially useless since if you're running in a debug build in a
debugger such that they are enabled, it will be even more obvious.
However, use assertions when the argument is saved for later use, so
the offender is obvious (this happens in class constructors most
often).

Brett

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to