Extended Type Design.

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Mar 20 13:12:33 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> 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

Huh? Wait a second, but won't D have the same issue, albeit with 
'final'? For example, suppose you have:
   final Foo foo;
then what is:
   typeof(&foo)
?





-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list