bearophile:
>> One solution is to "disable" some of the more error-prone syntax allowed in 
>> C, turning it into a compilation error. For example I have seen newbies 
>> write bugs caused by leaving & where a && was necessary. In such case just 
>> adopting "and" and making "&&" a syntax error solves the problem and doesn't 
>> lead to bugs when you convert C code to D (you just use a search&replace, 
>> replacing && with and on the code).<<


Kagamin:
>Why do you want to turn D into Python? You already has one. Just write in 
>python, migrate others to it and be done with C family.<


The mistake I have shown of using "&&" instead of "&" or vice-versa, and "|" 
instead of "||" and vice-versa comes from code I have seen written by new 
programmers at he University. But no only newbies can put such bugs, see for 
example this post:

http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00990.html
It says:
>People sometimes code "a && MASK" when they intended "a & MASK". gcc itself 
>does not seem to have examples of this, here are some in the linux-2.4.20 
>kernel:<

I want to copy the syntax that leads to less bugs and more readability, and 
often Python gives good examples, because it's often well designed.

Note that this change doesn't lead to less performance of D code.

Also note that G++ already allows you to write programs with and, or, not, xor, 
etc. The following code compiles and run correctly, so instead of Python you 
may also say I want to copy G++:

#include "stdio.h"
#include "stdlib.h"

int main(int argc, char** argv) {
    int b1 = argc >= 2 ? atoi(argv[1]) : 0;
    int b2 = argc >= 3 ? atoi(argv[2]) : 0;
    printf("%d\n", b1 and b2);

    return 0;
}

That can be disabled with "-fno-operator-names" while the "-foperator-names" is 
enabled by default. So maybe the G++ designers agree with me, instead of you.

Bye,
bearophile

Reply via email to