property functions
Adam D. Ruppe
destructionator at gmail.com
Sun May 16 15:47:55 UTC 2021
On Sunday, 16 May 2021 at 15:12:25 UTC, Nick wrote:
> Is this warning still valid?
The @property thing doesn't do much. All it does is change
typeof(a.prop) from function over to the return value of the
function. (Which actually makes it required for the range empty
and front things!)
But since it doesn't do much it makes it very easy to misuse it
too - putting it somewhere where it doesn't belong will NOT cause
the compiler to issue an error.
So that's why it is warned: the current behavior is extremely
minimal and if that expands and you misused it, you'll see broken
code down the line.
But on the other hand, @property has been a do-nothing for a
decade now, so I wouldn't expect that to change any time soon.
My general rule is to put it on something that should be
replaceable with a public data member. If you can't do that,
don't make it @property. In particular, do NOT put it on
something for the sole reason of not using () on the call.
@property is not really related to parenthesis syntax. Only use
it when it is specifically meant to be replaceable with a public
member.
More information about the Digitalmars-d-learn
mailing list