const sucks
Benji Smith
dlanguage at benjismith.net
Sat Oct 18 21:29:58 PDT 2008
John Reimer wrote:
> 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. :)
My understanding of the proposal was that "const by default" was only
for function parameters. And I agree with walter that it's a little but
wonky and unexpected.
But I liked it anyhow, and I think people could have easily gotten used
to the distinction in constness between function params and all other
variables. Especially since the compiler would always be able to catch
the mistake.
--benji
More information about the Digitalmars-d
mailing list