Fully transitive const is not necessary
Walter Bright
newshound1 at digitalmars.com
Wed Apr 2 15:17:32 PDT 2008
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.
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