Dicebot on leaving D: It is anarchy driven development in all its glory.

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Aug 29 16:34:29 UTC 2018


On Wed, Aug 29, 2018 at 01:02:54AM +0000, tide via Digitalmars-d wrote:
[...]
> Point being, there is a huge difference between what you were saying,
> and what you are saying now. "This data never changes" is a much
> better guarantee and check than "this code does not modify this data".
> You use const to make sure the data doesn't change, if you can't
> guarantee it doesn't change from any other code then I wouldn't say it
> is machine-verifiable.

You appear to be still misunderstanding how it works.  In D, if you want
to make sure the data never changes, you use immutable.  Const is for
when you want to make sure a piece of code doesn't modify the data (even
if the data is mutable elsewhere).  Both are machine-verifiable. As in,
the compiler can verify that the code never touches the data.  Immutable
provides the strongest guarantee (no code anywhere modifies this data),
while const provides a weaker guarantee (this code doesn't modify this
data, but somebody else might).

The usefulness of const is that you can safely pass *both* mutable and
immutable data through it, and you're guaranteed there will be no
problems, because const does not allow the code to touch the data. If
the code does not need to touch the data, then it could take the data as
const, and you could use the same code to handle both mutable and
immutable data.

All of this breaks down if you allow const to be overridden anywhere.
That's why it's UB to cast away const.


> So we would need another qualifier "tantamount" to be implemented then
> it seems.

I don't understand what you mean by this. Could you clarify?
 

T

-- 
Живёшь только однажды.


More information about the Digitalmars-d mailing list