Why do we have transitive const, again?
Mehrdad
wfunction at hotmail.com
Fri Sep 23 11:22:36 PDT 2011
On 9/21/2011 8:21 PM, Jesse Phillips wrote:
> On Wed, 21 Sep 2011 10:15:31 -0700, Mehrdad wrote:
>
>> I can't find the thread, but I remember someone (bearophile?) mentioned
>> that the reason we have transitive const is to support purity.
>>
>> I don't think I understand why this is necessary, though -- could
>> someone please explain why we have transitive const, and what problems
>> it fixes?
>>
>> Thanks!
> I came across this blog earlier, it may hold the answers you seek:
>
> http://www.reddit.com/tb/kkwch
>
> "One of the core difficulties in concurrent programming is trying to
> avoid the simultaneous reading and writing of data. Like with functional
> programming, concurrent programming is a lot easier when data can't
> change -- if you have no writes then you can't possibly have
> simultaneously reading and writing. However, unlike functional
> programming, logical const just doesn't cut it. If you were to give a
> reference to an instance of my Matrix class to two threads, and ask them
> both to compute the determinant then you could end up with an ugly race
> condition due to the memory writes in the caching mechanism. Here,
> physical immutability really does matter."
I don't see why immutability has anything to do with constness... would
you mind clarifying? Why does having transitive immutable also imply
that we /must/ have transitive const?
More information about the Digitalmars-d
mailing list