DIP23 draft: Fixing properties redux

Johannes Pfau nospam at example.com
Sun Feb 3 08:34:54 PST 2013


Am Sun, 03 Feb 2013 11:11:05 -0500
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> On 2/3/13 5:14 AM, Johannes Pfau wrote:
> > "If a function returns a reference, then assignment through the
> > paren-less call should work: "
> >
> > This is the only part where I would disagree. Why is this special
> > rule necessary if we have full @property support? I think this
> > would still allow too many false positives.
> 
> (As a note, this is the current behavior.)
> 
> The way I see it is this is a natural consequence of optional parens. 
> The name of a function without a "&" prepended or a "()" after it
> will invoke the function, and that's that.

I didn't think of it as a call without parentheses but it indeed makes
sense.

> 
> > * Is returning ref values from the getter OK?
> 
> I see no reason to disallow it at the language level.

You have to consider cases though where you have both a setter and a
getter returning a 'ref value'.

@property ref int value();
@property void value(int new);

* Is it valid to define both at the same time?
* Which one is used for assignment etc?

> > * Is taking ref values in the setter OK?
> 
> How do you mean that?

@property int value(ref int new);

IIRC that was just meant to complement the "is returning ref OK".
Usually nothing bad can happen. Although the ref parameter could be
converted into a pointer with some nasty tricks it's probably not the
job of the language to prevent that.




More information about the Digitalmars-d mailing list