Transitive const sucks
Sean Kelly
sean at f4.ca
Tue Sep 11 14:53:02 PDT 2007
Bruno Medeiros wrote:
> Sean Kelly wrote:
>> read operations. But for better or worse, D const has a different
>> aim. The goal is largely to produce a system which allows for
>> compiler optimization rather than to enforce some sort of logical
>> restrictions on behavior. I suspect this means that D apps won't look
>> very much like C++ apps in terms of how const is used, and the overall
>> utility for the average programmer may well be somewhat small.
>
> I'm don't think that's entirely true. 'invariant' the keyword is indeed
> made to allow several compiler and program optimizations, but 'const'
> the keyword is really for enforcing program contracts and restrictions,
> thus improving safety. I don't even think 'const' the keyword has any
> use whatsoever for optimization.
True enough. But the current design (ie. transitive and lacking
'mutable') is such that 'const' may have limited utility for UDTs where
logical state is not equivalent to physical state. I still think this
is fine, as I'd prefer something simple and understandable, but I wonder
whether this will be sufficient for enterprise programmers looking to
switch from C++ to D. Only time will tell, I suppose.
Sean
More information about the Digitalmars-d
mailing list