Re: Verify and expression
* Mark Van Peteghem:
Alf P. Steinbach schreef:
* Mark Van Peteghem:
... every assertion [should have] its own boolean that tells
whether *that* assertion should be displayed. A global boolean would
stop displaying *all* assertions.
Just use the file name and line number to identify the assertion.
That solution will probably work well, with just a small problem:
VERIFY may be nested, e.g.
return VERIFY(foo(VERIFY(bar())));
This is an excellent example of saving vertical space, but in such
cases the two VERIFY's will have the same file name and line number.
One of them may fail frequently, so the developer may stop displaying
it, but then he will not know when the other one fails.
I wish C++ had __COLUMN__ :-)
As I understand it this is in support of debugging, because otherwise
the developer could just change VERIFY to e.g. DONTVERIFY and recompile.
Well, turn it around, like
#define VERIFYIF( enabled, expr ) \
(enabled? VERIFY( expr ) : expr )
return VERIFYIF( bah27_enabled, foo( VERIFYIF( snarkum45, bar() ) ) )
where bah28_enabled and snarkum45 are enabling flags.
This exhanges one cost (work expended to find the thing that disables a
given assertion) for another cost (more visual clutter in client code),
but I think if the code is sufficiently spaghetti that this device is
"needed", then the little visual clutter won't matter, and it gives much
greater control & flexibility.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]