const, final, scope function parameters

Myron Alexander someone at somewhere.com
Mon May 28 04:05:47 PDT 2007


James Dennett wrote:
> 
> I disagree!  Experience (from C++) has shown me that a
> large proportion of "variables" are not changed after
> their initialization.  I find that it's true of most
> local variables (including function parameters), and
> using immutable objects with reference semantics is
> also fairly common.
> 

Would you please post some example. My experience in C, C++, and Java is 
different from yours. I'm not saying you are exactly wrong, I understand 
where you are coming from, especially with class instance references but 
my way of coding has more mutable variables than constants. I think it 
is a matter of program style and I don't mind writing "final Xx x = new 
Xx ();" which I do often in Java.

> The advantages in compiler checking mean that even if
> there is a (sufficiently small) additional cost in
> having the default be immutability, my experience
> strongly suggests that it would be worthwhile.  As
> I've said, I also find that the cost would be small,
> given how many "variables" aren't variable in clean
> code.  (Who knows, maybe this default could even
> encourage people to use new variables when they have
> a different value with a different meaning, rather
> than reusing a "convenient" local variable which was
> used for something else.  But now I'm dreaming.)

Once again, please post an example. I am curious to see your code style, 
maybe I can learn from it.

Regards,

Myron.



More information about the Digitalmars-d mailing list