@property - take it behind the woodshed and shoot it?

Jonathan M Davis jmdavisProg at gmx.com
Thu Jan 24 21:50:45 PST 2013


On Friday, January 25, 2013 14:35:08 kenji hara wrote:
> 2013/1/25 deadalnix <deadalnix at gmail.com>
> 
> > @function seems like an extra complication. Ambiguity between setter and
> > getter for @properties when UFCS come into play are not solved. Functional
> > style is impaired as you can't pass regular function around, just
> > @function
> > . You'll still find trap in generic code around the behavior of regular
> > functions.
> 
> That's a good point. We need to solve another ambiguity about top-level
> @property function which have a parameter, between top-level property
> setter and UFCS property getter.
> 
> module abc;
> @property int foo(int n);
> 
> void main() {
>   foo = 1;  // top-level property setter
>   1.foo;  // property getter with UFCS
> }
> 
> We cannot distinguish the two usages without adding any new features.

Well, better that then get rid of @property. The other big question is what to 
do with opDispatch, since unless we add the ability to overload on @property 
with opDispatch, then it can't work with both properties and non-property 
functions. Maybe opPropDispatch or somesuch could be introduced to solve that 
particular problem.

As for the top-level property problem, we could do something like 
@property(set) / @property(get) to distinguish. Or if we don't want the extra 
complication, we can just leave it. As long as you can use it as both a getter 
and a setter, it works, even if it still allows for weird uses. It would be 
nice to have a way to disambiguate it however.

- Jonathan M Davis


More information about the Digitalmars-d mailing list