Looking for documentation of D's lower-level aspects.

Marco Leise Marco.Leise at gmx.de
Wed Nov 9 06:29:02 PST 2011


Am 23.10.2011, 06:04 Uhr, schrieb Jonathan M Davis <jmdavisProg at gmx.com>:

> I'd have to go digging through the newsgroup archives to give all of the
> reasons but it basically comes down to the fact that people very rarely  
> want
> to pass containers by value, and the fact that C++ makes it so that the
> default behavior of passing container is to copy them is a frequent  
> source of
> bugs. In C++, containers are almost always passed by reference with & or  
> *
> rather than passing them by value, and if you forget to make the  
> function take
> or return via reference or pointer, it's a major performance hit. So  
> IIRC,
> Andrei thought that the fact that C++ containers are value types was a  
> big
> mistake of C++.
>
> - Jonathan M Davis

It is also what people not coming from C++ expect and I honestly think the  
containers should be more newbee friendly. RedBlackTree was a struct, that  
could not exist without at least one element in it. So instead of  
allocating it in the constructor of a class and using it in one of its  
methods, wherever you add an element you have to check if you have to  
create it first.
If the community is really split that much amongst people who want the  
most low-level containers as structs and people who want easy to use  
classes, then we actually need two container modules in Phobos. It is not  
done by saying, "you can wrap them in a class". Because then they are not  
easy to use in the first place.

Maybe we have so many arguments over how stuff should be done, because D  
can be used from scripting to writing OS kernels. There are probably three  
or more audiences with their expectations and in a few years we will see  
Tango resurrected by one of the thirds. Shouldn't those people with a very  
clear idea on how a container should be implemented, just implement their  
own or look for third party libraries and those who know little about  
containers can just use some whishy-whashy container that supports most  
common needs (can create empty, is by reference, has removal method, ...)?  
After all most of the performance stems from the used algorithm, not from  
going more low-level.

- Marco


More information about the Digitalmars-d-learn mailing list