Exceptional coding style

Era Scarecrow rtcvb32 at yahoo.com
Fri Jan 18 05:42:42 PST 2013


On Friday, 18 January 2013 at 10:49:52 UTC, Jonathan M Davis 
wrote:
> You really should know the precedence of at least the common 
> operators. For instance, I don't think that there's much excuse 
> for code like
>
> if((a == b) && (c != d))

  Unfortunately I've come across a few cases (and in dmd too) 
where compiles it wrong if you don't and get 
unwanted/unexpected/buggy behavior; So the code looks similar to 
that (but not by choice).

  I 'think' it was something like 'if(a + 2 > b)', but I'd have to 
dig them out to know for among hundreds of lines of code.

  The exact order of precedence has always eluded me and are a set 
of rules I'll never completely remember. However I do know that 
multiplication and division are above addition and subtraction, 
which is the only real place I've come to rely on it a few times 
to remove excess parentheses.


More information about the Digitalmars-d mailing list