Extended Type Design.
Bill Baxter
dnewsgroup at billbaxter.com
Fri Mar 16 16:42:15 PDT 2007
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.
This:
const int[int**][]*[char[]][3][17][3,17]* x;
is *already* unreadable (plus I don't think that [3,17] part is legal
D). If any reasonable programmer really did have a need for such a type
then they would probably break it up into aliases with some sort of meaning.
--bb
More information about the Digitalmars-d
mailing list