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

deadalnix deadalnix at gmail.com
Thu Jan 24 06:04:40 PST 2013


On Thursday, 24 January 2013 at 13:56:03 UTC, Jacob Carlborg 
wrote:
> On 2013-01-24 14:41, deadalnix wrote:
>
>> 3. @getter is an attribute. A function marked @getter is 
>> automatically
>> executed : () is added automatically :
>>     @getter void funName() {}
>>     funName; // function get executed.
>>     funName(); // Error, void is not callable.
>>
>> 4. @getter can be used as UFCS.
>>    @getter void funName(T t) {}
>>    T t; t.funName; // function gets executed.
>>    funName(t); // Error, funName require 1 argument, 0 given.
>>
>> 5. @setter is an attribute. A setter method can *only* be used 
>> in rhs of
>> an expression. The assigned value is used as argument.
>>    @setter void funName(T t) {}
>>    T t; funName = t; // function gets executed.
>>    funName(t); // Error, funName must be used in an assign 
>> expression.
>>
>> 6. @setter can as well be used as UFCS :
>>    @getter void funName(T t, U u) {}
>>    T t; U u; t.funName = u; // function gets executed.
>>    t.funName(u); // Error, funName must be used in an assign 
>> expression.
>
> What about @property(getter) and @property(setter) instead? 
> Otherwise we need two new built-in attributes.
>

I don't really care about the syntax. If any new attribute has to 
be added, they should be defined in some modules instead of 
builtin.

>> 8. method behave as functions :
>>     class A { void foo() {} }
>>     A a;
>>     static assert(is(typeof(a.foo) : void delegate())); // 
>> Pass.
>>     &a.foo; // deprecated NOOP for compatibility.
>>     a.foo(); // call a.foo
>
> The address operator wouldn't be needed to get a delegate for a 
> method anymore?

No, which would eliminate the difference behavior between 
function as variables and function defined in source code. This 
is a big step forward for functional style.


More information about the Digitalmars-d mailing list