On Tue, May 26, 2009 at 8:31 PM, Brett Wilson <[email protected]> wrote:

> Don't bother doing an assertion when the next line will crash anyway:
>  DCHECK(foo);
>  foo->DoSomething();


I mostly do what Brett does, but I do sometimes DCHECK in cases like this,
where the DCHECK is placed at the very beginning of a function, and is
really being used to indicate the function's preconditions.  This is
effectively an attempt to document in code that the developer of the
function explicitly never wanted the function called with NULL, and if you
fail the check, you should fix the caller rather than bandaiding with a
conditional (which can be a tempting fix if you lack the DCHECK and just see
someone dereference NULL).  I think this adds clarity.

Like Brett, I not only use CHECK for potential security problems but also to
indicate cases that will absolutely fail later on and we should just catch
with an easier-to-find crash now instead of a subtle bug later.

PK

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

Reply via email to