thoughts on immutability in D

Walter Bright newshound2 at digitalmars.com
Thu Sep 22 22:48:09 PDT 2011


On 9/22/2011 4:39 AM, bearophile wrote:
> Walter:
>
>> You're right. Logical const is only a convention, since it cannot be
>> enforced by the compiler.
>
> Even if it can't be enforced in 100% of the cases, I think it's still useful.
> So you need to look at the situation from a bit wider point of view.

It's worse than a half-implemented C++ feature, because the other half cannot be 
implemented. Even worse, when the app gets migrated to multiple threads, one 
inexorably falls into the tarpit of the Double Checked Locking Bug.

"logical const" in C++ is faith-based programming.

You'd be better off providing it as a library type that only allows read access 
to its state.


More information about the Digitalmars-d mailing list