Temporary suspension of disbelief (invariant)
Fawzi Mohamed
fawzi at gmx.ch
Wed Oct 27 13:55:50 PDT 2010
On 27-ott-10, at 22:41, Walter Bright wrote:
> Fawzi Mohamed wrote:
>> the only thing is that the invariant is not checked *after* those
>> method that destroy the object, it will be ok to require a special
>> name for that method (for example destroy, dealloc or similar) if
>> you want to avoid misusage.
>
> There is a method that does that, it's called the destructor. An
> invariant is not checked after the destructor is run.
ok I don't think that this is a major feature, or anything like that,
so I will stop arguing after this,
but I still believe that it would be useful.
The destructor is an example of a method that should not check the
invariant, but it does not address my use case, because one cannot
explicitly call a destructor, and there is an important difference
between a destructor called by the GC and a destructor called
explicitly: the one called explicitly can access the memory of the
object.
Not only that it might be useful for some methods to delete the object
itself.
A classical example is reference counting, the last release (the one
that sets the refCount to 0) should be able to delete the object.
It is not natural to make this impossible, or to force al reference
counted object to have no invariant.
More information about the Digitalmars-d
mailing list