const

Walter Bright newshound1 at digitalmars.com
Fri Mar 28 23:45:29 PDT 2008


Jason House wrote:
> Ummm... no, I don't think you do.  I guess I have a secret fear that except
> for exceptionally rare cases, invariant data will be pushed to the fringe
> of D.  The problem is that it's very hard to declare any data as invariant,
> and there's no implicit casts to invariant.  Excluding strings, it seems
> like 99% of normal usage will involve normal or const data.  In most cases,
> const occurs through an implicit cast.

I originally thought that would be true for strings, too, but it turns 
out that invariant strings are the overwhelming bulk of string usage. 
For most data structures, do they change once they're allocated and 
initialized? I don't know the answer to that, but I think we'll find out.


> Extending this further, nearly all D code will be unable to take advantage
> of the compiler optimizations... And fall short of the grand hopes for D,
> missing the window of opportunity that multi-core provides. 

Or that using invariants will involve a shift in the style of 
programming, and the advantages of invariants will provide the push to 
change the style (like it did for strings).


>> typeof(a) foo(const(T) a) { ... }
> 
> That's a very specific problem that I know has been under your radar, and I
> assume with time it'll get solved in a nice and clean way.
> 
> 
>> I'm worried it may have covariant/contravariant problems, but perhaps we
>> can work that out.
> 
> I don't know what you mean by that.

Imagine T is a base class, and a is a derived class. What is the typeof(a) ?



More information about the Digitalmars-d mailing list