09-Feb-2013 07:13, Michel Fortin пишет:
On 2013-02-08 23:53:30 +0000, Robert <jfanati...@gmx.at> said:

Ok. Here finally it is:

http://wiki.dlang.org/DIP26

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(); }


Yes, I too had thoughts along the same lines.

Though just writing some setters by hand and then adding:

mixin TrivialProperties!(_a, _b, _c);

should be doable. But it would be still an ugly boilerplate.

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.



--
Dmitry Olshansky

Reply via email to