Extended Type Design.

Don Clugston dac at nospam.com.au
Tue Mar 20 01:35:58 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> Don Clugston wrote:
>> Assuming that 'invariant' = really constant, 'const' = C++ 
>> pseudo-const...
> 
> Yah.
> 
>> 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'.
> 
> Great to hear that!

Sorry, I didn't explain myself very well. I meant that this proposal 
breaks 100% of all existing D uses of const.

  >> (3) I concede the problem of association with 'readonly' and ROM. But
>> the association between 'const' and 'constant' is pretty strong.
> 
> I think there's universal agreement that you can't express tersely the 
> two notions "const-as-in-C++" and "const-as-in-we-really-mean-it". 
> Probably it's best to just go with two terms and move on.

I completely agree with this. The gripe I have is that 'const' is a 
completely inappropriate term for 'const-as-in-C++'. It's a bizarre 
misnomer to use 'const' to mean "don't touch". The only benefit (albeit 
a considerable one) of this nomenclature is compatibility with C++ 
nomenclature, especially the term "const correctness".
D currently has a 'const' which actually means "constant", it seems 
dreadful to exchange that for a clearly inferior "don't touch" meaning.
I'm concerned that you may have spent so much time in C++ that you've 
become accustomed to "const" == "don't touch"; all of my previous posts 
have been arguing that this is a grossly unnatural association.

It is possible that the C++ misnomer is so entrenched that D needs to 
perpetuate it, even at the expense of breaking all existing D code that 
uses 'const'.

But then this really surprises me:

> final int a = 2;
> 
> void f(final int b)
> {
> }
> The choice of "final" in the second case prevents f from changing its argument,
 > and it's the free will choice of f's author. The "final" does not
 > influence f's signature or how other people use it.
 > It's just constraining f's implementation.

because it seems that that we still have 'const' surprises for C++ refugees.



More information about the Digitalmars-d mailing list