On 09/05/2018 03:35 PM, Meta wrote:
I think the only sane way to use asserts as an
optimization guide is when the program will abort if the condition does
not hold. That, to me, makes perfect sense, since you're basically
telling the compiler "This condition must be true past this assertion
point, because otherwise program execution will not continue past this
point". You're ensuring that the condition specified in the assert is
true by definition. Not having that hard guarantee but still using
asserts as an optimization guide is absolutely insane, IMO.
I'd certainly agree with this.
Frankly though, I've always found `-release` itself to be a horrible
thing to use, and I never go anywhere near it. It's a classic case of
premature optimization, pure and simple - and a dangerous one at that.
IMO the only time an assert should be omitted (note: *an* assert, none
of this module-level granularity stuff), even in release mode, is when
you can verify that leaving the assert in would be prohibitively
expensive: For example, frequent integrity checks on large trees, or
bounds-checking an inner-loop of a performance-critical codepath.
Removing an assert in release mode is exactly the same as declaring
"This part can't ever fail, so let's not worry about 'What happens if it
does fail?'" (if you're THAT certain, why did you write the assert there
in the first place???). TBH, I'm very surprised that Walter would ever
be in favor of it.