Stepping back and looking at constness from another angle.

Don Clugston dac at nospam.com.au
Tue Jun 5 07:54:16 PDT 2007


Sean Kelly wrote:
> That said, although I'm coming from a C++ background and though I have 
> used 'const' as a matter of course, it has never actually improved my 
> code.  I've never accidentally violated const behavior and had the 
> compiler catch the mistake for me, and dealing with const qualifiers and 
> overloads is an absolute nightmare at times.  I've got to admit that 
> I've become somewhat of a D convert in this respect.  I don't miss 
> 'const' and will probably be annoyed if these changes complicate the 
> code I write.

That's my experience too. Among curly-brace languages, only C++ has const, and 
C++ const is broken. No existing language does it properly, so it's hard to 
argue that it's a mandatory feature.

> The proposed changes are actually pretty decent from a conceptual 
> standpoint but I don't like the syntax.  Using three synonyms to 
> represent different facets of const behavior kind of stinks.  I'm sure 
> I'll get used to it with practice, but I worry that the const features 
> will hurt readability for those new to the language, and will complicate 
> code in the general case for little actual gain.

My thoughts exactly.

> What worries me most is that these new features will change things about 
> the language that I like--the .length/T[new] issue being the most recent 
> example.  Fritz's example is a core concept in much of Tango, and if it 
> breaks we're pretty much sunk.  If the syntax changes but it still 
> works... I suppose we'll see. 

I'm also a bit concerned that T[new] doesn't seem to be orthogonal to other 
const issues. It doesn't make sense to have an array which you can change the 
size of, but can't write to.

I hope it's all worth it.
Don.



More information about the Digitalmars-d mailing list