const sucks
John Reimer
terminal.node at gmail.com
Sat Oct 18 21:01:52 PDT 2008
Hello Walter,
> Bill Baxter wrote:
>
>> I think you mean "this option is being discussed *once again*". It
>> was discussed quite a lot before the current invariant/const was
>> implemented. The consensus was definitely that it was worth a shot.
>> But it did not get a shot.
>>
> Yes, it was discussed a lot.
>
>> I recall Walter's main argument against it was that local variable
>> really shouldn't be const-by-default since you're usually creating
>> them because you want to manipulate them. But then you end up with a
>> system where local variable declarations and parameter declarations
>> follow very different rules. "int[] foo" in one place means
>> something different from "int[] foo" in the other place. I'm not
>> convinced this would be that confusing, though. There could be other
>> problems with const-by-default in parameters, but that one doesn't
>> seem like such a big deal.
>>
> The problem is things like:
>
> void foo(int[] a)
> {
> int[] b;
> }
> so a is const, and b is mutable? That's very confusing. It gives the
> appearance of D having a lot of wacky and arbitrary semantic rules.
>
I'll have to go dig up all the past discussions on this (there were volumes
that I mostly skipped over).
My impression of mutable by default was more than function parameters.
Weren't we talking something like this when referring to "immutable by default":
// void foo(int[] a)
// {
// int b;
// mutable int c;
//
// /* block declaration */
//
// mutable
// {
// int d;
// int e;
// }
// }
'a' is an implied const (immutable) parameter.
'b' is const by default
'c', 'd', and 'e' are all declared mutable.
Isn't this what is meant by "constant by default"? I haven't described class
variables here, of course.
I'm nervous to comment further lest I have totally misunderstood what's going
on. :)
-JJR
More information about the Digitalmars-d
mailing list