assert semantic change proposal
John Carter via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 3 15:18:28 PDT 2014
On Sunday, 3 August 2014 at 20:05:22 UTC, bachmeier wrote:
>> 3. Undefined behavior.
Actually I have had an extensive battle within my own workplace
on this subject and I think I have a reasonable insight in to
both points of view.
It comes down to two opposing view of what we use asserts for.
My view, which I think corresponds with Walter's and Betrand
Meyer's, is that asserts define what correct behaviour is.
If an assert fires, your program is fundamentally defective in a
manner that can only be corrected by a new version of the program.
And the sooner you know that, preferably at compile time, the
better.
Continuing past such an assert inevitably results in defective,
possibly catastrophic, possibly flaky behaviour.
In the opposing view, an assert statement is a debug aid. In the
same category as a logging printf.
If it fires, it's "Huh. That's interesting. I didn't think that
would happen, but OK, it does. Cool."
Alas, these two uses have been given the same name. assert.
One resolution would be to create two assert interfaces, one that
the compiler pays attention to, and one that is just a "Huh.
That's interesting, I didn't expect that."
More information about the Digitalmars-d
mailing list