Does D have too many features?

Jonathan M Davis jmdavisProg at gmx.com
Sat Apr 28 18:35:51 PDT 2012


On Saturday, April 28, 2012 18:24:20 H. S. Teoh wrote:
> > * I hate C style struct initializers and would really like to see them
> > go, but for reasons that I don't understand, people actually use them
> > rather than using a proper constructor call, so I doubt that we could
> > get rid of them without a fair bit of complaining. I think that
> > they're completely redundant and very _un_D.
> 
> It's annoying to have to write a constructor whose only purpose is to
> copy arguments into field members. Many uses of structs don't need the
> encapsulation that ctors were intended for.

You don't have to. If you have

struct S
{
    int field1;
    float field2;
    string field3;
}

then you can do

auto s = S(5, 7.2, "hello");

The ability to do

S s = {5, 7.2, "hello"};

gains you _nothing_.

- Jonathan M Davis


More information about the Digitalmars-d mailing list