D const design rationale

James Dennett jdennett at acm.org
Fri Jun 22 23:04:28 PDT 2007


Walter Bright wrote:
> Sean Kelly wrote:
>> 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 don't think it is a peripheral issue.

No, you clearly don't.  But to many of us, it is a peripheral
issue, and the fact that you make it so central seems odd.

> It completely screws up optimization,

It has some detrimental effects on some optimizations.  It's
a huge aid to good design.

> is useless for threading support, and has spawned endless
> angst about why C++ code is slower than Fortran code.

Which will continue, even though C++ compilers can often now
beat Fortran compilers for speed.  (When used with idiomatic
C++ styles, rather than lower-level, C style extensive use
of pointers.)

>> Or am I missing something?
> 
> Yes, you've missed the distinction between a readonly view and a truly
> immutable value. 

I doubt that.

> That's not surprising, since my experience is that very
> few who are used to C++ const see the difference, and it took me a while
> to figure it out.

It's pretty trivial.  Which isn't to say that it's of no
use, but it's not complicated.  Then again, neither is the
C++ model of const, so maybe it depends on perspective.

-- James



More information about the Digitalmars-d mailing list