> bugs that have been very difficult to find, as they were 'fixed' by side effects of assert statements and hence didn't show up in debug builds.
In those cases, the assert() was used incorrectly. However, that's not a reason to include the assert code in release builds.
In a similar way, source code will often have troubleshooting code such as:
#if _DEBUG // or #ifndef NDEBUG
std::cerr << "inspect size: " << invoices.size() << std::endl;
// more debugging-related code ...
#endif
Just because some programmers mistakenly put unintended side-effects in between the #if_DEBUG/#endif doesn't mean we want that code in the release builds. The purpose of assert() and _DEBUG is to not include them in release builds.
Re:Assert() in the hands of bad coders
by marcosdumay on Tuesday March 28, 2017 @11:51AM
(#13977621)
You can't change your program without inserting some kind of side effect.
It may be timing in a multi thread system, extra memory available for an out of bounds array read, or even the CPU being kept busy and heating up or avoiding yielding to some other program.
Re:Assert() in the hands of bad coders
by dllthomas on Wednesday March 29, 2017 @04:36AM
(#13984380)
Your troubleshooting code flushed stderr. That's a side effect, and occasionally it will matter.
stderr is usually not buffered anyway.
Re:Assert() in the hands of bad coders
by dllthomas on Wednesday March 29, 2017 @04:45AM
(#13984424)
Usually.
Re:Assert() in the hands of bad coders
by minipci1321 on Tuesday March 28, 2017 @09:22AM
(#13976322)
First part of your message seem to be in contradiction with the second one, but anyways -- keeping asserts in the release image and incurring the penalty of added checks (execution speed + all these text strings stored in the read-only segment) does not make sense without the release-approving validation providing the exact coverage of all tested code. That can be tough to obtain.
Re:Assert() in the hands of bad coders
by FranOntanaya on Tuesday March 28, 2017 @09:37AM
(#13976424)
Asserts scare me, because I know someone out there is using them in place of validation without realizing they may be stripped out any time.
Several times I've had to track down bugs that have been very difficult to find, as they were 'fixed' by side effects of assert statements and hence didn't show up in debug builds.
If a check really can't be performed in the release version for performance reasons, just separate it out into a unit test.