@property - take it behind the woodshed and shoot it?

Maxim Fomin maxim at maxim-fomin.ru
Sat Jan 26 11:10:20 PST 2013


On Saturday, 26 January 2013 at 13:21:37 UTC, Jacob Carlborg 
wrote:
> It's always possible to avoid keywords in favor of syntax. 
> Example:
>
> Declaring a getter:
>
> int foo {}
>
> Just as a regular function declaration but without the 
> parentheses.
>
> Declaring a setter:
>
> void foo= (int value) {}
>
> Append an equal sign to the function name.

This looks nice, but I favor for C# properties.

The root of the issue is that in C/C++/D there is tremendous 
difference between object types and functions types (which are 
incompatible) and property is like a bridge between them - I 
think that is why the feature is demanded.

However in D a property is essentially a function. Few 
characteristics that are intrinsic to data types are typeof(prop) 
which is data type for properties and parenthesis-less access. 
There is no property as a special entity per se.

In C# property and getter/setter are separated, so there is no 
confusion between data and functions. In D it would look like 
this:

class A
{
     private int i;
     @property int foo // may be without @property at all?
     {
         get { return i; }
         set { i = @value; }
     }
}

In this solution property is not defined by naming of two 
separate functions and is independent of any function in general.


More information about the Digitalmars-d mailing list