Fully transitive const is not necessary

Craig Black craigblack2 at cox.net
Tue Apr 1 17:05:22 PDT 2008


"Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message 
news:fsu80i$2pj1$1 at digitalmars.com...
> "Craig Black" wrote
>> One idea that I had recently was that the const keyword could provide 
>> logical const (for developers) and the invariant keyword could provide 
>> transitive const (for the compiler).
>
> Making D not support logical invariant does not make it impossible to have 
> logically invariant functions as I have already demonstrated.  If there is 
> a way to legally implement logical invariant, then I think the language 
> should not impose that restriction.  Imposing a restriction that you 
> cannot have logical invariance is just going to be a nuisance for those 
> who want to do it, and it does not provide any benefits for compiler 
> optimization.

You are confident that Walter wrong about the benefits of transitivity. 
Honestly, I don't understand it deeply enough to agree or disagree.  I do 
think the const system should be easier for developers and having logical 
const will give us that.  If we get logical invariance too, then that's fine 
with me.  I was proposing a compromise since the D community and Walter each 
seem to have such strong opinions on the matter.

> The only place where it is important to ban logical const is for pure 
> functions as far as I can tell, and that can be dealt with when pure 
> functions are introduced.

I'd wager that Andrei/Walter have probably though about this quite a lot, 
and concluded that invariant transitivity was somehow the best solution to 
it.
Still, they could be wrong, and it's worth discussing, since even the 
smartest of us gets their wires crossed once in a while.

-Craig 




More information about the Digitalmars-d mailing list