The interaction of encapsulation and properties in D

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Wed Jul 10 20:44:02 PDT 2013


On Thursday, 11 July 2013 at 02:55:24 UTC, Luís Marques wrote:
> So, summing it up: even assuming that performance is not an 
> issue, does the advice to always encapsulate your member 
> variables (as one would do, for instance, in idiomatic Java) 
> actually make sense for D, or would you recommend using public 
> member variables when that is more straightforward, and the 
> indirection is not yet needed?

In general it seems people just use public fields. (I do, and 
sometimes annotated with @property). Considering the history this 
makes sense; optional parens "addressed" properties (see property 
discussions).

On of the main problems has been that public fields can be passed 
to ref parameters while this is not true for getters. I see this 
as a deficiency in @property but don't recall all the detail of 
the problem.


More information about the Digitalmars-d mailing list