@property needed or not needed?

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 19 21:40:53 PST 2012


On Monday, November 19, 2012 21:31:09 deadalnix wrote:
> Le 19/11/2012 10:02, Adam D. Ruppe a écrit :
> > On Monday, 19 November 2012 at 15:01:36 UTC, Andrei Alexandrescu wrote:
> >> Would you please start a DIP with a paste of this idea?
> > 
> > here it is:
> > http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP21
> > 
> > I tried to implement this a while ago and hit some pain after some early
> > success. The pain was trying to get assignments to work without breaking
> > other cases like returning ref.
> > 
> > My plan was to make any reference to a @property change to a CallExp or
> > whatever. But if you do that and it is on the left hand side of an
> > assignment, you do the wrong thing.
> > 
> > foo = foo + 1;
> > 
> > should generally become:
> > 
> > foo(foo() + 1);
> > 
> > but if there isn't a setter, we should leave it as foo() = foo() + 1;
> > and finding the setter is a bit of a pain. Then, of course, we ideally
> > want foo += 1 to work too..
> 
> This make it impossible to only define a getter only when one want to
> return by reference.

Returning by reference generally already defeats the purpose of defining a 
property function in the first place. Certainly, if you return by ref, it 
_definitely_ defeats the purpose of only defining a getter. By returning by ref 
from a getter, you've not only implicitly declared a setter, but you've made 
it impossible to verify anything about what's being set, because it's going 
through the ref rather than through an actual setter.

- Jonathan M Davis


More information about the Digitalmars-d mailing list