member arguments in D?

Steven Schveighoffer schveiguy at yahoo.com
Mon Apr 27 06:01:30 PDT 2009


On Mon, 27 Apr 2009 08:51:03 -0400, Daniel Keep  
<daniel.keep.lists at gmail.com> wrote:

>
>
> Steven Schveighoffer wrote:
>> ...
>>
>> There are three benefits I see to the proposal:
>>
>> 1. It saves typing.  This is not usually a big deal, except that this
>> sort of constructor is EXTREMELY common with container objects.
>
> Fair enough.
>
>> 2. It saves having to specify the type.  We get the same savings from
>> "auto," it should be similar here.  In fact, you could probably change
>> the keyword "member" to "auto".
>
> True, but...
>
>> 3. It's a little more self documenting.  You know when you see the
>> function signature, that what you pass in will at least start being the
>> initial value of the named member.
>
> class Act
> {
>     this(auto a, auto b) {}
>
>     // a million billion lines of code
>
>     private { int a; Wombat b; }
>
>     // another million billion lines of code.  And a pony.
> }
>
> Working out the type of a or b will be a major pain in the arse.

Just like:

void foo()
{
   int a, b;
   // a million billion lines of code
   auto c = a; // what type is a?
}

>> If you used auto as the keyword, you don't add a keyword.
>>
>> I'd vote for it.  Of course, I'd rather have inherited constructors
>> first ;)
>>
>> -Steve
>
> For me, the real nail-in-the-coffin is that you can do this with mixins.
>  Yes, grauzone, they're not pretty.  But they work and they don't
> require language changes.

Yes, the mixin Nick provided is handy.  I guess you are right.

-Steve



More information about the Digitalmars-d mailing list