byKey and byValue: properties or methods?

Jacob Carlborg doob at me.com
Wed Jan 18 04:33:45 PST 2012


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

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list