D const design rationale

Sean Kelly sean at f4.ca
Sat Jun 23 20:12:15 PDT 2007


Bruno Medeiros wrote:
> 
> I agree. Since in D, compile time values cannot be altered at compile 
> time, then any compile time value is immutable/invariant. Thus 
> const-as-storage-class is the same as invariant-as-storage-class and 
> those concepts should be cleared up.

The storage class vs. type constructor issue should be cleared up in 
general.  From the documentation, I had originally (falsely) assumed 
that invariant was a storage class only, when in reality the issue is 
much more simple.  So far as I can tell, as type constructors, 
'invariant' means the data will not change, period, 'const' means that 
the data can not be changed through the const-qualified reference, and 
'final' means the reference cannot be reassigned once set.  As storage 
classes, 'const' and 'invariant' mean exactly the same thing, and I'm 
still not entirely sure if there is a storage class interpretation of 
'final'.

As far as their application to non-reference variables is concerned, I 
think the overlap is unavoidable: they all mean effectively the same thing.


Sean



More information about the Digitalmars-d mailing list