Fully transitive const is not necessary

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 3 09:14:07 PDT 2008


"Walter Bright" wrote
> Jason House wrote:
>> Walter Bright wrote:
>>
>>> If you do away with transitive const, you cannot have invariant either.
>>> Const allows you to reuse code that works on invariants to work with
>>> mutables, too.
>>>
>>> Logical const just utterly breaks the whole system. Every scheme we've
>>> looked at for logical const winds up in some way breaking invariants. If
>>> invariants are broken, the advantages of them all just go away. I
>>> suspect that logical const is like perpetual motion - if you think
>>> you've solved it, you've just made a mistake somewhere <g>. I also
>>> suspect that the failure of logical const validates the D scheme of
>>> invariants as being correct - there shouldn't be any holes in it.
>>>
>>> You're right that invariant by itself is not enough to specify a pure
>>> function, a pure function also cannot read or write global state. But
>>> invariant is still a necessary condition, it's just not sufficient.
>>
>> Is it possible to describe what tricks the compiler can do given:
>>  A. transitive const      w/ mutable access to globals/statics
>>  B. transitive invariance w/ mutable access to globals/statics
>>  C. transitive const      w/ const access to globals/statics
>>  D. transitive invariance w/ invariant access to globals/statics
>>
>> It'd be extremely helpful to have that kind of discussion in the const 
>> FAQ. Without it, I feel like we're all discussing theoretical stuff with 
>> little
>> basis for our arguments.
>
> Sure, but static class members are *not* part of the transitive closure 
> state of the object. They're just global variables.

Neither are mutable member variables.

-Steve 





More information about the Digitalmars-d mailing list