Exceptional coding style
Jonathan M Davis
jmdavisProg at gmx.com
Fri Jan 18 02:48:33 PST 2013
On Friday, January 18, 2013 11:30:32 deadalnix wrote:
> If you believe you know operator precedence, you are probably
> wrong. And even if you are right, most other programmer don't.
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))
The parens just clutter the code, and any programmer worth their salt should
know that the comparison operators has higher precedence than the logical
operators. And programmers should definitley know the precedence of the
arithmetic operators, such that if they're putting parens around ever
expression using + or *, then there's a problem.
On the other hand, I can totally understand if someone is nervous about doing
stuff like
if(++*var == a)
I fully expect that your average programmer won't fully know the operator
precedence table. _I_ don't know it perfectly. But for the more common
operators, you should know it, and using extra parens in those cases just
makes the code harder to read.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list