At Google, 99% of assertions remain enabled at all times. There aresome nuances (as always, mindless dogma gets you nowhere), but in
general, if it should crash during testing, it should also crash in
production. The alternative is entering the forbidden realm of
undefined/unpredictable behavior. We really much prefer to debug a
clean crash with a traceback at the error site, rather than sieving
through weirdness after the fact.
This is true. Since I work mainly in infrastructure that never
directly sees a user, it is cheaper for us to crash immediately,
rather than have yet more error reporting machinery and spending time
to guess adequate answers to insane calls to functions. For us, it is
very cheap to crash, since upstream code will happily compensate, and
the worst case scenario is that we'll delay some batch/soft real time
processing by a couple of seconds. Obviously unacceptable for user
code. I should have better specified the context of my reply.
As you say, there has been endless debate on the subject, and it's
hard to come up with a definite "yes or no" rule. However, I'll note
that what you described for user-facing code, to log an error and try
to continue, is not the behavior you get with -DNDEBUG. By verbosely
logging/reporting an error, using the appropriate tools, you can get
as much information as a crash with traceback, which is identical in
terms of debugability as having crashed and reported the crash site,
except that users don't notice. -DNDEBUG however will just silently
skip all assertions and start stomping around on the stack, leaving
you with no idea of what the hell happened when the corruption does
eventually become critical enough to crash the process.
In other words, 99% of assertions and "non-fatal assertions" remain
enabled in production code. The choice for us is usually between "Do I
crash or make up an answer after verbosely reporting the failure?",
whereas the -DNDEBUG choice is "Do I report and crash, or silently
start unleashing the dragons?". Very different options :-)
- Dave
that what you described for user-facing code, to log an error and tryHowever, I'll note
to continue, is not the behavior you get with -DNDEBUG.