Porting D 1.0 code to 2.0, 'const' -> 'invariant'

Sean Kelly sean at f4.ca
Thu Jan 17 18:30:39 PST 2008


I know this issue has been discussed to death, but I'd like to once
again question the rationale behind changing the meaning of the 'const'
keyword between 1.0 and 2.0, given that the choice of keywords for const
features in 2.0 seems completely arbitrary.

In D 1.0, 'const' is essentially the same as 'invariant' in D 2.0.  It's
true that 'const' works just as well for the average situation in D 2.0,
but what if I have a ton of constants in a D 1.0 library that I want to
work the same way in D 2.0?  ie. in D 1.0 the 'const' label means I can
use the value without synchronization for multithreaded programming,
etc.  In D 2.0, this role is filled by 'invariant' and 'const' has been
weakened to mean "read-only view," which is not at all the same thing.

I suppose what I'm asking is how I should go about making a library
maximally cross-compatible with D 1.0 and 2.0, given the changed meaning
of 'const'?


Sean



More information about the Digitalmars-d mailing list