www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Shallow constness?

reply "Maxime Chevalier-Boisvert" <maximechevalierb gmail.com> writes:
Is there an attribute that can make member variables of a class 
read-only without having to declare them as const or immutable 
(const all the way down)? I saw that one can define a getter 
function without a setter to achieve this behavior, but that 
seems like a little bit of a hack.
Jul 23 2013
parent "Dicebot" <public dicebot.lv> writes:
On Tuesday, 23 July 2013 at 18:01:58 UTC, Maxime 
Chevalier-Boisvert wrote:
 I saw that one can define a getter function without a setter to 
 achieve this behavior, but that seems like a little bit of a 
 hack.
As far as I am aware, it is not a hack, but recommended practice. It actually does make sense - what you want has nothing to do with actual mutability of a member (at least within D concept of mutability) but is more like a tool for controlling access to it.
Jul 23 2013