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. - a On Tue, May 26, 2009 at 5:01 PM, Evan Martin <e...@chromium.org> wrote: > > In many places we have "shouldn't-happen" situations where a functon > might return NULL or false. > Coming from working on Google code you might be tempted to use > CHECK(foobar != NULL). > > But in client software, things that should never happen end up > happening all the time because of someone's strange computer setup or > cosmic rays. Our pattern is: > > 1) If it is just "this is highly unlikely", attempt to recover from the > problem. > 2) If it is "this shouldn't happen, and if it does a developer should > learn about it", use something like > if (!keyboard_has_spacebar) { > NOTREACHED() << " this keyboard is crazy, maybe our detection code > is wrong?"; > return false; // attempt recovery anyway > } > 3) If it really is something that's so bad that it's a security > problem if we continue, you should use CHECK(). But these should be > very rare. > > > > --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---