Newbie: copy, assignment of class instances

bearophile bearophileHUGS at lycos.com
Thu May 27 14:14:45 PDT 2010


Larry Luther:

> There are many things that I like and I strongly agree with the failings
> of C++ mentioned in the docs.

D is designed by people that have a good experience of C++, but while probably D avoids some C++ problems, it surely introduces a number of new issues :-)


> I don't like the asymmetry between structs
> and classes.  I don't see why structs can't have inheritance.

One of the first answers given here is that this D design avoids slicing bugs. See my other answer for more.


> I haven't
> had a memory leak problem in C++ for many years so the need for a GC seems 
> minor.
> I can only assume that it's needed to support strings and dynamic arrays.

A GC introduces other kind of leaks when there is a reference alive to an memory block that is supposed to be dead and not used any more. This can even be caused by the not precise nature of the current D GC, it can mismatch something for a pointer to a GC-managed memory zone, keeping it alive. For example in programs that use large associative arrays this seems a problem.

If you assume the presence of the GC this changes the way you write code. In theory you can be more relaxed. In practice D GC is not... well, you have to keep your eyes open anyway.


> I'm pushing forward on the assumption that I'll discover the paradigm that
> will make everything fall into place.

If you have some Java programming experience then you probably have nothing to discover regarding this aspect of D programming (here the main difference is that Oracle Java GC is more precise and quite more efficient).


> For example it took a great deal of time to 
> learn that "private" can be used several ways:

One of the good things of D design is that it tries to be uniform/consistent, in this case all other attributes can be used in the same ways :-)


>   I'm anxiously waiting for something of the quality of the "Annotated C++ 
> Reference Manual".

The problem here is that D is not very strictly defined in the first place, so it's harder to write a very strict D reference manual :-) But Andrei book is about to come out, that can be seen as a kind of official D2 reference.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list