On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote:

There are a lot of discussions in the forums about how @property
should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when I should use the @property tag?

Thx.
Eric

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;

or

struct myArray(T)
{
    T[] arr;
    @property size_t memSize() { return arr.length * T.sizeof; }
}

Other than that, don't use it. Ordinary functions can be called without parenthesis anyway.


Using those ideas you shouldn't run in to any surprises.

Reply via email to