A better assert() [was: Re: std.unittests [updated] for review]
Adam D. Ruppe
destructionator at gmail.com
Sat Feb 5 09:25:18 PST 2011
bearophile:
> The semantics a not D-expert expects from assert(something) is to
> test that something is "true". For a class reference this means the
> pointer is not null.
This is the core of our disagreement: I think an object is not
"true" if it's invariant fails. It means the object is completely
invalid, no different than if it was a null pointer. It's unusable.
The sooner this check is done, the better, so we can figure out
where it went wrong.
> One more "interesting" example:
That makes sense, it's still analogous to if() like you'd expect.
Actually, I wonder if doing if(obj) should check it's invariant
too with classes, both for consistency with assert and getting
that check done even more often.
More information about the Digitalmars-d
mailing list