Invariant and pre/post-conditions order

Walter Bright newshound2 at digitalmars.com
Thu Jan 19 17:38:05 PST 2012


On 1/19/2012 4:08 PM, Jonathan M Davis wrote:
> On Thursday, January 19, 2012 17:29:28 bearophile wrote:
>> If I am mistaken please I'd like to know why the current design is better
>> (or maybe why it's just equally good). Thank you :-)
>
> Honestly, I don't think that the order is all that critical, since all of the
> same assertions are run in either case. But conceptually, the invariant is for
> verifying the state of the object, whereas the post-condition is for verifying
> the state of the return value. And the return value doesn't really matter if
> the object itself just got fried by the function call. Not to mention, if your
> tests of the return value in the post-condition rely on the state of the
> object itself being correct, then your tests in the post-condition aren't
> necessarily going to do what you expect if the invariant would have failed.
>
> I have no idea what Walter's reasoning is though.

My reasoning is it (1) doesn't make any difference and (2) it's always been like 
that - and if it did make a difference, it would break 10 years of existing code.


More information about the Digitalmars-d mailing list