Extended Type Design.

Don Clugston dac at nospam.com.au
Mon Mar 19 09:25:33 PDT 2007


Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> kris wrote:
>>> So, "invariant" is already a keyword ... what about that?
>> I completely missed that one. I think it's a good idea to look into it 
>> as a candidate for a qualifier name. Thank you.
> 
> I agree. I think:
> 
> final
> const
> invariant
> 
> for the three cases looks pretty good.

Assuming that 'invariant' = really constant, 'const' = C++ pseudo-const...

It's better than super const. However:
(1) I would want to go through all my existing D code and change 100% of 
my usages of 'const' to 'invariant'.
(2) although (1) could be avoided with the rule that 'const' on a 
declaration implicitly means 'invariant', this would then mean that to 
match a 'const' value, you use 'invariant'; but to match a non-const 
value, you use 'const'. That's horribly confusing.
(3) I concede the problem of association with 'readonly' and ROM. But 
the association between 'const' and 'constant' is pretty strong.

The problem remains that in:

const int a = 2;

void f(const int b)
{

}

a really is a constant, but there is nothing constant about 'b'!

How about 'protected'?
It seems to cover the 'don't touch' meaning pretty well...



More information about the Digitalmars-d mailing list