D const design rationale
Bill Baxter
dnewsgroup at billbaxter.com
Fri Jun 22 13:39:14 PDT 2007
Sean Kelly wrote:
> Walter Bright wrote:
>> Sean Kelly wrote:
>>> Walter Bright wrote:
>>>> In C++, sometimes const means invariant, and sometimes it means
>>>> readonly view. I've found even C++ experts who don't know how it works.
>>> Odd. The C++ system always seemed extremely simple to me.
>>
>> It isn't. I run into people all the time who are amazed to discover
>> that const references can change.
I was surprised to find that p->q[0]=5 is always ok for a
const C*p. Learned that from reading the const doc just now.
> Matter of opinion, I suppose. The C++ design was immediately clear to
> me, though it obviously wasn't for others. I grant that the aliasing
> problem can be confusing, but I feel that it is a peripheral issue.
I vaguely remember C++'s const taking some time for me to internalize.
But it seems natural now. So I'm not too worried about it. I also have
a feeling that invariant won't show up very often except at the
module-level scope. So I'm not so worried about how to grok the odd
combinations of const/invariant and what they mean. I have trouble with
groking "int * const * const **foo" in C++ but that's never caused me
any problem in an actual programming task. In the end there are just a
handful of common usages. It might be nice to have these collected and
documented somewhere.
--bb
More information about the Digitalmars-d
mailing list