Remus

John Chapman johnch_atms at hotmail.com
Thu Nov 22 04:19:03 PST 2012


On Thursday, 22 November 2012 at 11:55:08 UTC, Namespace wrote:
> On Thursday, 22 November 2012 at 07:14:38 UTC, Jacob Carlborg 
> wrote:
>> On 2012-11-21 21:48, Namespace wrote:
>>
>>> Hm, I like the Idea.
>>> But I would prefer:
>>> private:
>>>    int _bar in(int val) {
>>>        _bar = val;
>>>    } out {
>>>        return _bar;
>>>    }
>>
>> The point was to make the syntax short. I wouldn't consider 
>> this much of an improvement.
>
> IMO is too short not always the best. Therefore I like the C# 
> syntax with set and get. The aquivalent of this in D is IMO 
> 'in' and 'out'.

I believe Jacob is referring to C#'s auto-implemented properties: 
http://msdn.microsoft.com/en-us/library/bb384054.aspx

The compiler generates the get/set pair and backing store from 
the user's single-line declaration.

So,

    @property int bar();

would expand to:

   private int bar_;

   @property void bar(int value) {
     bar_ = value;
   }

   @property int bar() {
     return bar_;
   }


More information about the Digitalmars-d-announce mailing list