property syntax strawman

Michel Fortin michel.fortin at michelf.com
Sun Aug 2 03:27:27 PDT 2009


On 2009-08-02 03:43:43 -0400, Walter Bright <newshound1 at digitalmars.com> said:

> Having optional parentheses does lead to unresolvable ambiguities. How 
> much of a problem that really is is debatable, but let's assume it 
> should be resolved. To resolve it, a property must be distinguishable 
> from a regular function.
> 
> One way is to simply add a "property" attribute keyword:
> 
>    property bool empty() { ... }
>    property void empty(bool b) { ... }
> 
> The problem is that:
> 
> 1. there are a lot of keywords already
> 2. keywords are global things

Glad to see you're giving it some tought. :-)


> The alternative is to have a unique syntax for properties. Ideally, the 
> syntax should be intuitive and mimic its use. After much fiddling, and 
> based on n.g. suggestions, Andrei and I penciled in:
> 
>    bool empty { ... }
>    void empty=(bool b) { ... }

I like that. But then (just a question) can you do:

	void empty+=(bool b) { ... }
	void empty++ { ... }
	void ++empty { ... }

?


> The only problem is when a declaration but not definition is desired:
> 
>    bool empty;
> 
> but oops! That defines a field. So we came up with essentially a hack:
> 
>    bool empty{}
> 
> i.e. the {} means the getter is declared, but defined elsewhere.
> 
> What do you think?

I'd prefer this, which can't be misinterpreted as an empty statement:

	bool empty { ... }

It also happens to scale well to any function delcation:

	void foo() { ... }
	void empty=(bool b) { ... }

The way I see it, the other function declaration syntax would still 
work, except for property getters where you'd need this special one.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list