Let's not make invariants const

Jonathan M Davis jmdavisProg at gmx.com
Fri Aug 3 19:34:49 PDT 2012


On Friday, August 03, 2012 12:36:41 H. S. Teoh wrote:
> 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 think that it's more of a problem of not being able to call non-const 
functions and the like. I'd definitely be against mutating anything in an 
invariant, but if your type doesn't work with const very well (and the recent 
debate about Object and const highlights how that can be a big issue), then 
forcing stuff like invariants and contracts to be const is problematic.

- Jonathan M Davis


More information about the Digitalmars-d mailing list