Let's not make invariants const
bearophile
bearophileHUGS at lycos.com
Fri Aug 3 12:40:18 PDT 2012
H. S. Teoh:
> IMO, if you need to be changing stuff inside invariants, then
> you're using it wrong. Invariants are intended to verify
> program logic, not to do things like altering object state. The
> point is to be able to compile with invariant code turned off,
> and still have the program work exactly as before.
I agree, modifying the state of the struct/class instance is not
the job of contracts and invariants. D contract programming is
already not tidy, so better to not make it even more messy.
In a perfect world invariants and contracts should be pure too!
Bye,
bearophile
More information about the Digitalmars-d
mailing list