What is the state of @property?
bauss
jacobbauss at gmail.com
Thu Aug 25 13:23:25 UTC 2022
On Thursday, 25 August 2022 at 13:18:38 UTC, Andrey Zherikov
wrote:
> 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).
I'm really not sure what you mean.
Currently @property doesn't really do anything in this regard, so
I imagine that the code would work the same without @property, no?
More information about the Digitalmars-d
mailing list