D
DeMarcus
Hi,
What are the reasons, except for speed, to disable asserts?
Thanks,
Daniel
What are the reasons, except for speed, to disable asserts?
Thanks,
Daniel
DeMarcus said:What are the reasons, except for speed, to disable asserts?
Victor said:If you can answer "what are the reasons for disabling debug printouts?"
then you already know the answer to your question.
Therefore I have a follow up question. I don't like macros (let's take
the macro discussion later) so therefore I thought speed could be saved
by using lambdas like this.
newAssert( [&](){ realAssert( myPtr != nullptr ); } );
inline newAssert( std::function<void()> myLambda )
{
if( assertEnabled )
myLambda();
}
Now the speed difference is only one if-statement.
There are a few things I miss doing like this, like having the
expression itself in the assert printout,
but if we focus on the speed
saving discussion, is this a smart way of postponing tasks that may be
disabled?
I was thinking that this idea could be used with normal
printouts as well where we maybe want to construct a big amount of
detailed data from current scope.
It's not as simple, of course. Not all
diagnostic elements get removed from the final product. You can decide
that you need to keep asserts (or even give the user a debug version of
your program sometimes), all depends on what your goals are.
Andrew said:[...]Therefore I have a follow up question. I don't like macros (let's take
the macro discussion later) so therefore I thought speed could be saved
by using lambdas like this.
newAssert( [&](){ realAssert( myPtr != nullptr ); } );
inline newAssert( std::function<void()> myLambda )
{
if( assertEnabled )
myLambda();
}
I was thinking that this idea could be used with normal
printouts as well where we maybe want to construct a big amount of
detailed data from current scope.
..by switching scopes and reducing the data to zero?
(I agree with you that assert is mostly a debug tool but other
clowns who frequent this channel do not).
DeMarcus said:What are the reasons, except for speed, to disable asserts?
[it] all depends on what your goals are.
What are the reasons, except for speed, to disable asserts?
If you can answer "what are the reasons for disabling debug
printouts?" then you already know the answer to your question.
Assertions are debugging and testing tools. Once the program
has been debugged (and is presumed correct),
they are nothing but hindrance for using the program. If some
code does nothing for the result of using the program, why
keep it there?
If you can be 100% assured that your program has absolutely no
errors, then perhaps what you're saying would make sense. As it
is...
Making a debug version available to a user on line
and then working with the user to pinpoint the problem
is the way to go I think. Otherwise, the debug
version may fall into the wrong hands and be used to
reverse engineer your application.
Brian Wood
What are the reasons, except for speed, to disable asserts?
tonydee said:There are some valid reasons, but they're infrequently encountered.
James Kanze mentions games... a good example where flawed operation
may still provide an acceptable end-user experience, and - for some
issues such a rendering - there may be nothing more at risk than the
visual experience presented. Saving game state that doesn't meet
assertions is more of an issue if old state is thereby destroyed.
You could also have a situation where you're using an assert to check
for specific inputs you're aware of and have tested thoroughly -
wanting to know in a very attention-grabbing, un-ignorable way the
instant any other input arrives. Still, in production you may have
general-purpose handling that you expect is adequate, but just haven't
had the opportunity to test with this new input. An assertion in a
development build might model this situation well enough for your
purposes, but personally I'm loath to do anything that makes putting a
development build into production riskier.
And, while some people argue that continuing after an error invites
erroneous results that are worse than none at all, the way I view it
is that fast evolution of large software systems involves management
of a spectrum from rock-solid thoroughly-tested critical functionality
to little nice-to-have relatively unimportant features. For example,
document integrity after a cut/paste operation, versus a "non-
technical readability ratio" you're adding in for wow value and to try
to out-feature the competition despite no customers actually asking
for it. While an assertion failing in the former may (arguably)
justify stopping a production process, it can easily be better to
continue after a minor bug in the latter. If your style is to use
assertions in preference to logging to emphasise that the issue is a
development bug, then continuation requires disabling assertions in
the production build. Similarly, if you add some benchmarking code -
not part of the core functionality, but to guide further development -
you don't necessarily want to assert/abort because subtracting one
timestamp from another gave a negative or impossibly large result.
You might just log an warning and get on with life, but logging
doesn't give the same level of assurance of stamping out such issues
during the development process.
Cheers,
Tony
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.