const, final, scope function parameters

Bill Baxter dnewsgroup at billbaxter.com
Sun May 27 14:07:52 PDT 2007


Regan Heath wrote:
> Walter Bright Wrote:
>> Frank Benoit wrote:
>>> Perhaps we look at it from the wrong side.
>>>
>>> If we want to change the D language to make it more const, the keywords
>>> 'const', 'invariant'... are probably the wrong choice.
>>>
>>> How about restricting keywords and add their opposites: 'mutable',
>>> 'once' (write once) and then make every variable declaration const by
>>> default? Each variable/parameter needs to be made modifyable with
>>> modifiers if needed.
>> I think having to write:
>>
>> 	mutable int x;
>>
>> instead of:
>>
>> 	int x;
>>
>> just isn't going to please people.
> 
> Ahhh, I think I see what you're concerned about.  As in this example?
> 
> mutable int gx;
> void foo(int y) {  //y is scope const final
>   mutable int z;
> }
> 
> where the global and local scope ints 'gx' and 'z' are not supposed to be const scope final.
> 
> Why can't we apply 'scope const final' to function parameters only?

Because he said "that seems to throw people for a loop."  I'm guessing 
the qualm is that in this:

int* gx;
void foo(int* y) {
   int* z;
}

all three of those declarations sure look the same to an uninitiated C++ 
(or current D) user.  So I think by "throws people for a loop", Walter 
means "isn't obvious to C++ converts".  But well... all I have to say to 
that is why would you expect any form of const by default to look 
natural to a C++ user?  It's just not going to.  But the hope is they'll 
thank you for it in the long run.

--bb




More information about the Digitalmars-d mailing list