property syntax strawman

Kagamin spam at here.lot
Mon Aug 3 06:39:00 PDT 2009


Andrei Alexandrescu Wrote:

> I'd like to have an easy enough syntax for defining read-only properties 
> (often in my code). With the proposed syntax, one writes
> 
> bool empty { ... }
> 
> and calls it a day, but with the elaborate getters and setters there are 
> two scopes to get through:
> 
> bool empty { auto get() { ... } }
> 
> which is quite some aggravation.

How about syntactic sugar for this?

Let's have two types of property declaration
1. Regular property. Only op* functions allowed inside, no field declarations, no normal functions.
bool empty
{
  opGet(); opSet();
}
2. Concise readonly property. Only procedural statements allowed inside, op* functions are disallowed.
bool empty
{
  if(length==0)return true;
}
3. It's not quite an aggravation to declare a readonly property.
bool empty { opGet(); }



More information about the Digitalmars-d mailing list