Extended Type Design.

Dave Dave_member at pathlink.com
Sat Mar 24 21:48:46 PDT 2007


Andrei Alexandrescu (See Website For Email) Wrote:
> Dave wrote:
> > Ok, this maybe somewhat selfish since I haven't used D's 'const' much, but I really have to agree with Derek -- the exceptions need to be dropped <g>
> > 
> > Based on past NG discussions on 'const', I believe it is so important to get this right the first time that the exceptions need to be removed in favor of the most intuitive and consistent syntax.
> > 
> > Since the current "const char[] str = 'XYZ'"; semantics would prevent both str or its elements from being modified, we could make a reasonable assumption that code already properly tested and running (and just recompiled with a new compiler) would not break anyhow, correct?
> 
> 
> I think this is a valid point.
> 

Maybe a few more justifications for getting rid of the exceptions:

- It's more effort and complexity to add the exceptions to the compiler, docs., etc...
- IIUC, a search-and-replace operation from 'const' to 'final' or 'final const' could 'fix' most current source code.
- It would be better to have to add the exceptions later (based on programmer feedback) than to add them and then have to remove them.
- The other case you mentioned (i.e.: const real MyPI = 3.14159;) should not be a problem with most currently correct D code (like const char[] str = "XYZ"; above). Could this case (a value type constant) warrant an error with the new compiler?

Thanks,

- Dave





More information about the Digitalmars-d mailing list