Feature request - simpler constructors

Janice Caron caron800 at googlemail.com
Fri Sep 21 00:43:41 PDT 2007


I tried to look at tango source code, but I can't seem to connect to
dsource.org right now. Hopefully that's a transient problem.

I know that Sun's official Java tutorial (see
http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.html)
tells you to do exactly what I've been talking about. I quote:

 public Bicycle(int startCadence, int startSpeed, int startGear) {
     gear = startGear;
     cadence = startCadence;
     speed = startSpeed;
 }

C++'s syntax for doing this is rather complicated and confusing, but I
should add that the full blown C++ mechanism of allowing member
variables to be assigned with arbitrary expressions in not needed in
D. It is needed in C++ because everything is passed by copy, meaning
that copy constructors and destructors have to be run as values are
copied to and from functions. That would not be needed in D because
classes are copied by reference, and structs require no copy
constructor. Thus

 : (x,y,z)

would suffice for us. I think it would be marvellous.



More information about the Digitalmars-d mailing list