Poll: Would you like to try const-by-default or not?

Ary Manzana ary at esperanto.org.ar
Mon Jun 11 19:17:26 PDT 2007


Jarrett Billingsley escribió:
> This is not a discussion thread.  I think we've discussed enough.  :)
> 
> Basically there are these possible const implementations (there are others, 
> but for the sake of simplicitly, I'll keep this poll to 2):
> 
> 1) C++ style const, where you mark anything that should be const as such.
> 
> 2) Parameters are const-by-default, and must be marked mutable otherwise. 
> Locals, fields etc. are still mutable by default.
> 
> Walter doesn't want to stray from option 1, because 2 is basically "too 
> weird."
> 
> Please reply with your choice, and maybe a small explanation of why.
> 
> I'll start this off by saying I'm definitely willing to try option 2.  I 
> never really learned const-correctness in C++ because it looked so damned 
> awful.  Option 2 makes more sense to me. 
> 
> 

2) const by default.

Most of the time a program transforms data:

T1 var1 = someVar.doSomething();
if (var1.hasProperty()) {
	T2 var2 = var1.doSomethingElse();
	return var2.foo();
} else {
	T2 var2 = var1.doSomethingDifferent();
	return var2.bar();
}

At least high level programs, I guess.

Maybe even var1 is used afterwards for something else... and if it's 
mutable by default and some other programmer in my team comes and 
assigns a value to it in the middle, it may break something. Marking 
which variables are meant to change is safer, I think.



More information about the Digitalmars-d mailing list