Extended Type Design.

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Tue Mar 20 08:54:07 PDT 2007


Don Clugston wrote:
> Frits van Bommel wrote:
>> Don Clugston wrote:
>>> 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.
>>
>> I don't see how this would be a surprise for anyone coming from C++. 
>> This is exactly how 'const' works for value types, isn't it?
> 
> Yes. The point is that for some uses of C++ const, you have to use 
> 'const', while for others you need to use 'final'. I feel that this 
> weakens the argument for using the word 'const' in the C++ sense. The 
> hypothetical C++ refugee is still going to have culture shock when using 
> D const.

I think the shock will be mollified by the explanation that const is for 
the stuff "before the star" and final is for the stuff "after the star".

const char *const s = "hello"; // C++

Many C++ programmers complain about this syntax, finding it silly.


Andrei



More information about the Digitalmars-d mailing list