Temporary suspension of disbelief (invariant)

Walter Bright newshound2 at digitalmars.com
Wed Oct 27 11:20:35 PDT 2010


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.

It's not an invariant if it only works some of the time.

It's like C++ and the mutable keyword, which allows an escape from the const 
rules. Which makes C++ const fairly useless.

A person should be able to see the invariant in a class declaration, and know 
that it offers a guarantee. He should not be required to read over everything 
else in the source code looking for the absence of a method that disables it.


More information about the Digitalmars-d mailing list