C++ traps that D2 doesn't avoid yet?

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 6 10:45:53 PST 2008


"ore-sama" wrote
> bearophile Wrote:
>
>> This page lists a lot of C++ traps and pitfalls in a short space. I 
>> assume D has to avoid or render meaningless a quite high percentage of 
>> them.
>> The nice thing of that list is that I think most (maybe 80-90%) of those 
>> traps and pitfalls (and several others that aren't listed, like allowing 
>> simple syntactical mistakes like putting a & where a && was requires or 
>> vice versa, etc) can be avoided by a language like D
>> but seeing the huge troubles C++ has gone to be as much compatible as 
>> possible with C I'd say that keeping the original C semantics when it is 
>> known to cause troubles is _always_ bad. In such situations I prefer a 
>> language that acts correctly
>
> Most of these pitfalls are actually features, not bugs and are used 
> massively. Like implicit casts, & instead of &&, assignment instead of 
> comparison etc. These are pitfalls for novice programmers. Why bother?

They can be made more difficult to do mistakenly.

Even experienced developers fall into some of these traps.  I know I 
occasionally fell into this trap:

if(x);
  x->doSomething();

But no more with D, because it's not allowed.  Those kinds of things can be 
easily prevented, and are common mistakes by all programmers.

I appreciate any effort by the compiler to not compile code that can be 
definitively declared as invalid.  It saves me time and bugs, and that is 
worth a lot.

-Steve 





More information about the Digitalmars-d mailing list