DIP26: properties defined

Jacob Carlborg doob at me.com
Sat Feb 9 07:22:28 PST 2013


On 2013-02-09 04:13, Michel Fortin wrote:

> This is pretty much exactly how I think properties should work. There's
> two possible benefits you may to have overlooked…
>
> One benefit of the "@property T foo;" syntax that does the boilerplate
> code for you over using a plain variable: the getter and setter
> generated are virtual in a class, so a derived class can override them.
> Doesn't work with a plain variable.
>
> Another possible benefit that we could have is the ability to use the
> default getter but to provide your own setter implementation by just
> declaring it:
>
>      @property int a;
>      @property void a(int value) { __a = value; refresh(); }
>
> Much cleaner than this:
>
>      private int _a;
>      @property int a() { return _a; }
>      @property void a(int value) { _a = value; refresh(); }
>
> It's really great to not have to write boilerplate functions when
> default behaviour is perfectly fine. I've been using Objective-C for a
> while now and the recent changes where it automatically synthesize a
> variable, a getter, and a setter when declaring a property (unless you
> provide your own) are truly delightful.

I completely agree, I really like it. Do we want to be able to use 
attributes like "final", and perhaps others, when declaring a property 
field:

@property final int a;

The lowered functions would have the "final" attribute attached to them 
self.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list