What is the state of @property?
Andrey Zherikov
andrey.zherikov at gmail.com
Thu Aug 25 13:18:38 UTC 2022
On Thursday, 25 August 2022 at 03:26:32 UTC, Ki Rill wrote:
> It's not recommended to use it, yet people do continue using it
> anyway... I see it in people's code. So, was it finalized, but
> docs weren't updated? Or is it still half-backed? And what is
> the issue?
Why is it not recommended?
It's useful when you need to evolve API and migrate users from
one data member to another, for example:
```d
struct S
{
@property string old_member() const { return new_member; }
string new_member;
}
```
Or when you want to do some audit:
```d
struct S
{
@property string member() const
{
writeln("'member' is used by ", environment["USER"]);
return _member;
}
string _member;
}
```
I have no objections to deprecate `@property` attribute but I
believe D must support the use case when `obj.mem` expression
calls `obj.mem()` function (this is usually called property
functions).
More information about the Digitalmars-d
mailing list