Temporary suspension of disbelief (invariant)

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 27 09:59:16 PDT 2010


On Wednesday, October 27, 2010 07:33:58 Fawzi Mohamed wrote:
> An issue I encountered in D1 with invariant is using delete: I have a
> method that deletes the current object, and obviously then any
> invariant would fail.
> It would be nice to have a way to disable invariant in that case.
> In D2, as delete is not allowed anymore (if I got it correctly) this
> is not a problem.

Except that calling a function on a deleted object would not be desirable, so 
having the invariant fail at that point would be a _good_ thing. If anything, 
you'd want _all_ function calls on a deleted object to fail invariant or no 
invariant, because none of them should be happening in the first place.

clear() in D2 does (or at least did - I don't know what it's current state is) 
put an object in its default state prior to any constructor call which would 
likely violate any invariant, which, on the whole, is a good thing as well. 
However, there was discussion of making a cleared object have a nuked vtbl which 
would be even better, since then all function calls on it would fail period.

- Jonathan M Davis


More information about the Digitalmars-d mailing list