Fully transitive const is not necessary

Jason House jason.james.house at gmail.com
Wed Apr 2 16:44:21 PDT 2008


Walter Bright wrote:

> If you do away with transitive const, you cannot have invariant either.
> Const allows you to reuse code that works on invariants to work with
> mutables, too.
> 
> Logical const just utterly breaks the whole system. Every scheme we've
> looked at for logical const winds up in some way breaking invariants. If
> invariants are broken, the advantages of them all just go away. I
> suspect that logical const is like perpetual motion - if you think
> you've solved it, you've just made a mistake somewhere <g>. I also
> suspect that the failure of logical const validates the D scheme of
> invariants as being correct - there shouldn't be any holes in it.
> 
> You're right that invariant by itself is not enough to specify a pure
> function, a pure function also cannot read or write global state. But
> invariant is still a necessary condition, it's just not sufficient.

Is it possible to describe what tricks the compiler can do given:
 A. transitive const      w/ mutable access to globals/statics
 B. transitive invariance w/ mutable access to globals/statics
 C. transitive const      w/ const access to globals/statics
 D. transitive invariance w/ invariant access to globals/statics

It'd be extremely helpful to have that kind of discussion in the const FAQ. 
Without it, I feel like we're all discussing theoretical stuff with little
basis for our arguments.

PS: I went to digitalmars and couldn't find the const FAQ.  It's not linked
to from the normal FAQ and is not included in the left-side bar on the D
2.0 page(s).




> 
> Peoples' troubles with const seem to stem from attempting to defeat it
> in one way or another. While defeating const is legal and trivial in
> C++, D tries to close those doors.





More information about the Digitalmars-d mailing list