thoughts on immutability in D

Rainer Schuetze r.sagitario at gmx.de
Mon Sep 26 23:50:15 PDT 2011



On 26.09.2011 08:32, Jonathan M Davis wrote:
> On Monday, September 26, 2011 08:14:31 Rainer Schuetze wrote:
>> Which finally brings us back to the original question: What does
>> immutable guarantee in the face of non-pure property getter functions?
>
> immutable guarantees that when an object is immutable, none of its member
> variables will _ever_ be altered. It guarantees _nothing_ about variables
> external to the object, and impure function can access pretty much anything
> external to an object via module level or static functions or variables, so an
> impure function could return literally _anything_ and could vary on every call
> even if the object is immutable. Any impure member function which uses values
> external to the object has to worry about the thread-safety of those values.
> The thread-safety of the object itself is guaranteed, but that's all.
>
> - Jonathan M Davis

Thanks for clarifying. My conclusion still is: if the immutable data 
structure implementation is unknown or complex enough that you cannot 
make sure the implementation of property getters are not screwed up, you 
are relying on faith similar to head const in C++.


More information about the Digitalmars-d mailing list