byKey and byValue: properties or methods?

Jacob Carlborg doob at me.com
Wed Jan 18 06:05:58 PST 2012


On 2012-01-18 14:47, Steven Schveighoffer wrote:
> On Wed, 18 Jan 2012 07:33:45 -0500, Jacob Carlborg <doob at me.com> wrote:
>
>> On 2012-01-18 09:30, sclytrack wrote:
>>>
>>>>
>>>> Is it practical or realistic to throw it out at this stage? I don't
>>>> know. But there are reasons to.
>>>
>>>
>>> I hope we are not dropping properties
>>> regardless of the syntax of how to call them.
>>>
>>> Keep @property
>>> Keep methods-as-properties
>>>
>>> ---------------------------------
>>> (a) No ()
>>>
>>> obj.property = "test";
>>> string str = obj.property;
>>>
>>> obj.method = "string";
>>> obj.method("first");
>>> string str = obj.method;
>>> obj.method("first", "second");
>>>
>>> ---------------------------------
>>> (b) Optional () for methods
>>>
>>> obj.property = "test";
>>> string str = obj.property;
>>>
>>> obj.method = "string";
>>> obj.method("first");
>>> string str = obj.method;
>>> string str = obj.method();
>>> obj.method("first", "second");
>>>
>>> ---------------------------------
>>> (c) Mandatory () for methods
>>>
>>> obj.property = "test";
>>> string str = obj.property;
>>>
>>> obj.method = "string";
>>> obj.method("first");
>>> string str = obj.method();
>>> obj.method("first", "second");
>>>
>>> ---------------------------------
>>> (d) Property and Method separated. (Is this the goal for -property?)
>>>
>>> obj.property = "test";
>>> string str = obj.property;
>>>
>>> string str = obj.method();
>>> obj.method("first");
>>> obj.method("first", "second");
>>>
>>> ---------------------------------
>>>
>>> Who likes (a) ?
>>>
>>> Also I think that the @property opDispatch() looks weird.
>>
>> I would like this:
>>
>> property:
>> getter - parentheses are not allowed
>> setter:
>> * equal sign is required
>> * parentheses are not allowed
>>
>> method:
>> no parameters - parentheses are optional
>> parameters:
>> * parentheses are required
>> * equal sign is not allowed
>>
>> Examples:
>>
>> obj.property; // legal
>> obj.property = 1; // legal
>> obj.property(); // error
>> obj.property(1); // error
>>
>> obj.method; // legal
>> obj.method(); // legal
>> obj.method(1); // legal
>> obj.method = 1; // error
>
> what about:
>
> int x = obj.method; // passes by your rules, but I think should be illegal

I could go either way with that one. But I think I prefer optional 
parentheses.

> I think the parentheses should only be optional on void-returning methods.
>
> Otherwise, I agree with your list.
>
> -Steve


-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list