any news on const/invariant?
Walter Bright
newshound1 at digitalmars.com
Mon Nov 26 15:02:57 PST 2007
Derek Parnell wrote:
> On Mon, 26 Nov 2007 14:11:25 -0800, Walter Bright wrote:
>
>> Jason House wrote:
>>> Walter Bright Wrote:
>>>
>>>> Denton Cockburn wrote:
>>>>> Any update on the status of the const/invariant changes?
>>>> Yes, it's about done.
>>> How about documentation of how const will work. Is this essentially
>>> what was originally posted in the "const is broken" thread? Or are
>>> there new surprises in store for us?
>> I don't remember the details of that, but the nutshell version is:
>>
>> 1) no more final for variables
>
> Is the keyword in this context now a syntax error?
It's just ignored.
>> 2) no more 'head const' or 'tail const', it's all just 'const'
>
> Does that mean that if X is const then neither the bits in X and the bits
> referenced by X can be modified (though the X symbol)?
Const and invariant are transitive. C++ const is not transitive, leading
to programmers establishing a *convention* for transitive const. But it
being an unenforced convention means it is not reliable.
>> 3) ditto (2) for invariant
>
> Does that mean that if X is invariant then neither the bits in X and the
> bits referenced by X can be modified by anything?
Right.
>> It should be working as one would intuitively expect it to.
>
> If the answer is 'yes' to the couple of questions above ...
> (a) is there a form of the syntax that allows 'X' to be modified but not
> what it references?
Yes, transitive const applies downwards, not upwards.
> (b) is there a form that prevents 'X' from being modified but allows what
> it references to be modified?
No. There is no language typing support for 'logical const' (i.e. const
structures with mutable members). Many C++ people have argued
passionately for logical const, but I have become strongly convinced
that the notion is fatally flawed.
More information about the Digitalmars-d
mailing list