byKey and byValue: properties or methods?

Steven Schveighoffer schveiguy at yahoo.com
Wed Jan 18 05:47:04 PST 2012


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 think the parentheses should only be optional on void-returning methods.

Otherwise, I agree with your list.

-Steve


More information about the Digitalmars-d mailing list