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

Walter Bright newshound1 at digitalmars.com
Thu Nov 6 12:32:50 PST 2008


Steven Schveighoffer wrote:
> To be honest though, I more disagree with your assertion that only novice 
> programmers are affected.  I sometimes make these types of mistakes, and I 
> definitely don't consider myself a novice ;)

The if(e); is illegal in D because back in the 80's, the best programmer 
in the company came to me asking me why his for loop executed only once:

    for (i = 0; i < N; i++);
         ...

He had spent all afternoon chasing this problem, first isolating it to 
the loop and then trying to figure it out. He was sure it was a compiler 
bug. I stared at it for a while, mystified too, until I saw the ;.

There is no advantage to having the language accept such code, and even 
if the programmer wrote it on purpose, it *looks* like a bug. Code that 
looks right should be right, and code that looks wrong should be wrong.



More information about the Digitalmars-d mailing list