What does C++ do better than D? - StackOverflow.com

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Aug 1 18:29:18 PDT 2011


On 8/1/11 6:30 PM, Adam Ruppe wrote:
> Peter Alexander wrote:
>> 1. The fact that you can't copy const struct objects containing
>> reference types.
>
> I recently hit a similar problem. web.d uses a ParameterTypeTuple
> to fill in arguments to the functions it calls in a generic way.
>
> With "in" arguments, assigning to the tuple isn't allowed! It says
> "can't modify const".
>
> I decided to just not use const in there, and cast it away in the
> wrapper function. I'm not happy with that, but I don't know what else
> to do. (I generally like D's const and immutable, but blarg there are
> some rough edges and I don't even know how to fix the design.)

I know how to fix the design (in fact the implementation, the design is 
sound). It's just ever so difficult to find the time to prioritize for it.

Overall I feel Peter's post on stackexchange did more bad than good (of 
course that doesn't mean he had the right; I'm just writing this under 
the hypothesis he meant well and he'd be interested ). Within the 
confines of the community, discussing such issues is welcome and 
healthy. Mentioning these to the outside blows the issues out of 
proportion and conveys the wrong message to someone coming anew to D.

Plus, C++'s type system is marred by issues, so the statement has 
correctness issues to start with. Const is a mix of storage type and 
type qualifier; even most experts have no idea about that, and the 
minority of experts who do know about the distinction have difficulty 
figuring which is in effect when. Type deduction with functions and 
const is essentially a collection of special cases. Pointer to member 
functions have a type, but it can't be named, spelled, or used. 
Functions taking char* still accept string literals (compilers 
increasingly override that, but the rule is in the standard for C's 
sake). There is no way to convert a void* to a pointer to function, 
meaning all dynamic loading facilities must operate outside the 
standard. There is no way to specify or figure out alignment. Slicing 
polymorphic objects is legit. And so on and so forth.

C++'s type system problems have been trodden over a million times and 
they might have became as invisible as that carpet stain in the hallway. 
That doesn't mean they're not there.


Andrei


More information about the Digitalmars-d mailing list