Possible @property compromise

Jacob Carlborg doob at me.com
Wed Jan 30 06:38:23 PST 2013


On 2013-01-30 00:55, Rob T wrote:

> Given how D currently works, I don't see how we can realistically
> implement a function as a drop in replacement for a variable and expect
> code to continue working as if nothing had changed.
>
> One of the bigger problems is that the getter returns by value, not ref,
> so everything that expects a ref return will fail.
>
> I expect to make precise variable emulation through properties will
> require a lot of compiler magic, and there will be inevitable bugs and
> conflicts that follow. I really don't see that there's enough value with
> the property concept to justify the costs of precise variable emulation.
>
> You know a lot more about implementing compiler magic than I do, so I'll
> ask you if you think the effort is doable enough to justify having
> property functions that can act like a drop in replacement for existing
> variables?

Implement this:

struct Foo
{
     @property int a;
}

Lowered to:

struct Foo
{
     private int a_;
     @property int a () { return a_; }
     @property int a (int value) { return a_ = value; }
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list