How do you properly use immutable on class members?

Ali Çehreli acehreli at yahoo.com
Tue Mar 29 19:42:11 UTC 2022


On 3/29/22 10:58, Fruitful Approach wrote:

 > so I end up undoing all the places I inserted it.

That's what I do as well, which proves my 'const' object only hoped to 
be 'const'. I never say "I have to respect my decision from 10 minutes 
ago, so I must keep this object const." Nope! 'const' is replaced with 
'auto' instantly. :)

'const' and 'immutable' on member variables are trouble because they 
make objects unassignable. (But you said 'class', so there is no such 
issue with them in D anyway.) But is that too bad? Is assignment 
overrated anyway? I don't know... :/

Ali



More information about the Digitalmars-d-learn mailing list