Uniform Function Call Syntax(UFCS) and @property

kenji hara k.hara.pg at gmail.com
Thu Mar 3 12:32:44 PST 2011


It seems to me that you think only combination of member-variable like
property and UFCS.
My suggestion is consider global-variable like property as well.
example:
  @property int global_var(){...}  // getter, int n = global_var;
  @property void global_var(int n){...}  // setter, global_var = 10;

I think that global variable like setter function and member-variable
like getter function occur ambiguity.
Getter and Setter are the opposite meaning.

Kenji

2011/3/4 Jonathan M Davis <jmdavisProg at gmx.com>:
> On Thursday, March 03, 2011 09:14:36 kenji hara wrote:
>> Current D's property-like function call is too loose.
>> Under current rule, following both two statements being legal.
>> void f(int n){...}
>> f(10);
>> f = 10;
>>
>> If @property will separate these two syntax definitely, but UFCS will
>> introduce the ambiguity again:
>> // future code
>> @property void f(int n){}
>> f = 10;
>> 10.f;
>>
>> We also definitely separate 'this' value where UFCS is allowed.
>
> UFCS is supposed to be allowed _everywhere_, or it isn't universal, and if it
> isn't universal, I don't really such much point to it personally.
>
> And I don't see any real ambiguity in those functions even with UFCS. A module
> level function which returns void and takes only one parameter shouldn't be a
> legal property. A property function should be a function which operates _on_
> something. It's an abstraction for a member variable. So, a getter property on a
> user-defined type should return a value and take nothing and a setter property on
> a user-defined type should return void and take a single parameter. But a getter
> property which isn't a member function should return a value and take a single
> parameter which is the type which the property is on, and a setter property
> which is a setter function should return void and take two parameters - the type
> which the property is on and the value to set.
>
> As such, I see no ambiguity. What you're suggesting complicates things and
> restricts UFCS such that it isn't really all that useful. The whole point of
> UFCS is that it be universal.
>
> - Jonathan M Davis
>


More information about the Digitalmars-d mailing list