On Sunday, 20 July 2014 at 18:14:29 UTC, Eric wrote:

Use @property when you want a pseudo-variable or something that might be conceptually considered a "property" of the object, i.e. to do this:

auto blah = thing.someProperty;
thing.someProperty = blahblah;


This is basically what I suspected.  But why
write:

@property int getValue() { return(value); }

You should use nouns to name properties and verbs to name methods. D has optional parentheses, so you can write x=getValue; So @property is generally not needed except for the case when the method returns a delegate, which in its turn can be implicitly called, so there's an ambiguity, which @property was meant to solve (but AFAIK in the end it didn't). It also serves as a documentation, that the method should be viewed as a property. Initially optional parentheses were meant as an easy implementation of properties, and @property wasn't meant to exist until the ambiguity with the delegate was understood.

Reply via email to