Const, strings, and other things.

Robert Fraser fraserofthenight at gmail.com
Mon Nov 12 16:40:21 PST 2007


Jarrett Billingsley Wrote:

> What my thoughts boiled down to is that constness seems useful for 
> strings and not much else.  I suppose it could be useful for other kinds 
> of arrays, but overwhelmingly the use cases for const seem to be for 
> strings, and constness helps to make some operations with strings more 
> efficient.  Other than that, constness for other types seems more like a 
> logical convenience.  So you want to return a const(Foo) where Foo is a 
> class reference?  How often do you need to do that?  Passing const refs 
> -- have YOU ever had a bug where you tried to modify a const ref param 
> that was caught by the const?

Coming from a Java background, I agree with you quite a bit. However, I have run into one case where having const in Java would help a lot (although I think if I can get my debugger to set a modification watchpoint, it'll be a non-issue). Somewhere in the Descent semantic analysis, some static members that are supposed not to change are being somehow modified. Since the codebase is large, figuring out where exactly thats happening is proving problematic.

That said, I agree -- having a const string would be good enough for software engineering purposes for me. But I think Walter wants to be able to optimize based on invariantness.



More information about the Digitalmars-d mailing list