Suggestion: object const'ness

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat May 20 19:40:55 PDT 2006


"ChristopheBourez" <ChristopheBourez_member at pathlink.com> wrote in message 
news:e4kik9$1ntj$1 at digitaldaemon.com...

> It should be interesting to have a const'ness ala C++, I mean, the ability 
> to
> declare methods that do not modify the state of objects.
> Any comments?

I think it's all just a convoluted mess.  Considering how many levels of 
const-ness you can have (can I modify the reference?  or the contents 
thereof?  how about arrays?  can I change their contents, or just where they 
point?), and the obvious problem that you can cast it away (without the need 
for ASM, something Tom mentioned), I don't see how it could be implemented 
orthogonally while still being useful.  Const also means different things to 
different people, so there'd be a lot of dissention over exactly what it 
should do.

Having taught myself how to program C++ from a relatively old book, I never 
really learned to write "const-correct" code.  Even so, having written some 
C++, and a lot more in D, I've _never_ run into a bug caused by my 
modification of something that I wasn't supposed to be modifying.  I'm sure 
some people have, but the concept of "const" seems like an overkill solution 
for it.

I really don't want to see D code looking like some C++ code, where const is 
applied to absolutely _everything_:

const int[] const func(const float x, const char[] const str) const;

Wheeeeeee. 





More information about the Digitalmars-d mailing list