D const design rationale
Sean Kelly
sean at f4.ca
Sat Jun 23 10:18:14 PDT 2007
Walter Bright wrote:
> Sean Kelly wrote:
>
>> Perhaps I misunderstood the "must be known at compile-time" clause.
>
> That's only when you use invariant as a storage class. It doesn't apply
> when you use it as a type constructor.
>
>> Can 'invariant' apply to dynamic arrays that will remain unchanged
>> once initialized?
>
> Yes.
Ah, now it's coming clear. For some reason I thought 'invariant' only
worked as a storage class. I guess my only real issue with the design
now is the use of the word 'invariant' -- it's rather long :-) In some
respects I'd almost prefer using 'const' for 'invariant' and 'view' for
'const'. But I think this suggestion has come up before and 'view' was
shot down because it's both a noun and a verb?
> In my work I use almost no static data--it's all generated
>> on the fly or loaded from some data source. Will 'invariant' help to
>> make my code more optimal?
>
> Not with the current compiler, because the back end hasn't been modified
> to take advantage of it. But the potential is there.
Yeah, I don't care if the compiler does it now, only that the potential
is there. After all, this discussion is about the design, not the
implementation.
Thanks for explaining things. I'm coming to understand the reasoning
behind the design you've chosen.
Sean
More information about the Digitalmars-d
mailing list