dmd warning request: warn for bitwise OR in conditional

Yigal Chripun yigal100 at gmail.com
Sat Jan 30 15:59:30 PST 2010


On 23/01/2010 20:10, Nick Sabalausky wrote:
> "Yigal Chripun"<yigal100 at gmail.com>  wrote in message
> news:hjek8e$4j0$1 at digitalmars.com...
>>
>> uint a, b; // init to whatever
>> bool c, d; // ditto
>>
>> auto r1 = a AND b; //  a&  b
>> auto r2 = c AND d; // c&&  d
>> ...
>> AND stands for whatever *single* syntax is chosen for this.
>>
>
> Yuck, that amounts to language-enforced operator overloading abuse, just
> like the common mis-design of overloading '+' to mean both 'add' and
> 'concat'.
>
>

"No operator was abused during the making of this post"...

unlike the string concat. case, both the bit ops and the bool ops have 
the exact same semantics (OR, AND, NOT) and the only difference is the 
scale . This is already represented by the type system and there is no 
need to repeat yourself a-la Java:
Foo foo = new Foo(); // is this really a Foo?

in the same spirit of things, no-one argues for a different addition op 
for each integral type:
int a = 2 + 4;
long b = 2000000 ++ 400000000000; // LOOOOONG addition

it ain't assembly language.

Also, it prevents common bugs and makes for more readable code. In the 
same vain, I'd be willing to remove other shortcuts that are come causes 
of bugs, like the assignment inside the if condition and not requiring 
explicit check in if condition.
"if (foo is null)" instead of "if (foo)".

Last thing, Stop with the moronic "oh my god, I need to type a few more 
characters" attitude. (Yes, bearophile, that's you.)
FACT - code is read 1000 times more than it's written. readability IS 
important. No, xfoo is NOT a legit name for a function, call it lazyFoo 
if you want to emphasize its laziness. are you still trying to save 3 
bytes in the age of cheap Tera-byte HDDs?
In the same spirit, stop removing f*cking vowels from words. You ain't 
coding in Hebrew.



More information about the Digitalmars-d mailing list