Assertions in Programming
The cluster debates the proper use of assert macros, especially in C, questioning whether they should be enabled in production builds for invariant checks or limited to debug mode, versus using regular runtime checks for errors.
Activity Over Time
Top Contributors
Keywords
Sample Comments
C has always had Asserts for that reason.
Plus, assert() is commonly used for runtime checks, not static analysis.
The most questionable thing is why did they keep the assert in production code. Looks like unfinished job to me.
Well, the lesson here is to not use asserts for that task. Asserts are by definition checks that are meant not to be included in release versions. If checking some invariant matters to you in the actual application (as opposed to just being a debugging convenience), then do a normal check.
Doesn't matter. Assertions should be used for things that are always true (barring bugs in the program). That isn't the case here.
What's bizarre about asserts being disabled if you explicitly ask for it?
Assertions are in the code. And they can really be helpful.
It's undefined behavior if the assert triggers in production. It's too greedy for minor performance benefit at the risk of causing strange issues.
Isn't that what assertions are for?
Probably because this case was something more akin to an assert than an error check.