const sucks

John Reimer terminal.node at gmail.com
Sat Oct 18 21:26:52 PDT 2008


Hello John,

> 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
> 


Sorry, I really should have reviewed this before posting.  I see that const-by-default 
was referring to parameters only.  Shame on me.

Even so, I think the argument that it would make D confusing if parameters 
are const and variables are mutable by default merely falls to convention: 
it mostly disruptive because it's such a big change from C++. Perhaps that's 
a big argument against it, but ultimately it's usefulness might be more important? 
 I can't say much for or against, I suppose, so I'll avoid saying much more 
until I understand this better.  I suppose the other matter discussed was 
concerning class objects as Andrei indicated, which appears to be discussed 
much in past threads, if I'm not mistaken.

-JJR





More information about the Digitalmars-d mailing list