Really nooB question - @property
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 20 11:00:14 PDT 2014
On Sunday, 20 July 2014 at 17:59:07 UTC, John Colvin wrote:
> 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.
Oh, but don't expect the compiler to enforce this and please
don't use the -property flag, it will only cause you pain.
More information about the Digitalmars-d-learn
mailing list