www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: property syntax strawman

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(); }
Aug 03 2009