Temporary suspension of disbelief (invariant)

Rainer Deyke rainerd at eldwood.com
Tue Oct 26 19:04:26 PDT 2010


On 10/26/2010 18:00, bearophile wrote:
> All this looks bug-prone, and surely hairy, but it looks potentially
> useful. Is it a good idea to design a class that uses such temporary
> suspension of the invariant?

I think invariants should be checked whenever a public member function
is called from outside the object.  If setting the object to an invalid
state from outside is valid, then clearly the state isn't really invalid.

On the other hand, if the object itself calls it own public member
functions, then no invariants should be checked.  Not being able to call
public member functions while the object is temporarily in an invalid
state is too strict.  This is a problem that I actually ran into while
using D, and one of the reasons for why I stopped using invariants.


-- 
Rainer Deyke - rainerd at eldwood.com


More information about the Digitalmars-d mailing list