Feature request - simpler constructors

Lars Ivar Igesund larsivar at igesund.net
Fri Sep 21 00:55:31 PDT 2007


Janice Caron wrote:

> 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.

I'm pretty sure that Kris is saying that the assigning to member variables
in constructors is such a simple and trivial thing to do, that adding
possibly confusing, implicit syntax for it is unnecessary.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango



More information about the Digitalmars-d mailing list