Extended Type Design.
Derek Parnell
derek at psych.ward
Fri Mar 16 14:34:48 PDT 2007
On Fri, 16 Mar 2007 14:05:17 -0700, Andrei Alexandrescu (See Website For
Email) wrote:
> Dan wrote:
>> Wow...
>>
>> I've never put this much thought into const/final stuff. Ultimately, the program *cannot* prevent data in memory from being changed. It can at best prevent you from accidentally changing it; hence final and const declarations mean "I don't want anyone to change these, can you raise an error if someone tries to within D?"
>>
>> Also, the problem breaks down to 'what am I declaring const?'. If I declare:
>>
>> const int* x; // is it the pointer, or the int?
>>
>> This doesn't seem important until you get to:
>>
>> const int[int**][]* x; // now what is it?
>>
>> Ultimately, you have this problem going through each and every pointer, array and value. You could theoretically write this:
>>
>> const int[int**][]*[char[]][3][17][3,17]* x; and now what are you going to do? declare it:
>>
>> final const final final const const final final final final final const?
>> Even final const! super const! final! const! doesn't work, in fact I agree it makes it worse.
>>
>> Good luck getting readability with that.
>>
>> Ultimately, something else needs to be developed.
>>
>> Perhaps a character we can use in alongside each item on the type declaration, or we need to be able to hit the whole line in one blow..
>>
>> Just my penny.
>
> I'm not sure what this is meant to convey.
It is trying to convey the difficultly in determining which
'final'/'const'/'super const' instance refers to which part of the
declaration.
Given ...
int[int**][]*[char[]][3][17][3,17]* x;
and I want to make the 'x' immutable and the 'char[]' immutable, how does
one write the declaration? Where does one place the 'final'/'const'/'super
const' and where do the parenthesis go?
--
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell
More information about the Digitalmars-d
mailing list