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

Artur Skawina art.08.09 at gmail.com
Sat Jan 26 13:48:42 PST 2013


On 01/26/13 20:10, Maxim Fomin wrote:
> 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.

Hmm, the current state of them being defined by two separate functions really
isn't ideal. But introducing new keywords or magic identifiers just for this
does not seem right.

   class A
   {
       private int i;
       int foo {
           out { return i; }
           in(int v) { i = v; }
       }
   }

or

   class A
   {
       private int i;
       @property foo {
           int out { return i; }
           in(int v) { i = v; }
       }
   }

artur


More information about the Digitalmars-d mailing list