Re: C
Re: C
- Subject: Re: C
- From: Hsu <email@hidden>
- Date: Sat, 30 Aug 2003 21:19:15 -0700
On Saturday, August 30, 2003, at 08:13 PM, Clark Cox wrote:
If your expressions are long enough that someone would need help
understanding them, then you should try writing shorter, more concise
expressions. So, you would never write:
z = x + y * w;
You would instead write this?:
(z = (x + (y * w)));
I would probably write
z = x + (y * w);
but if forced at gunpoint, I'd still choose the second. If I had to
scan the code looking for a bug 5 years later, the latter is going to
make it much easier to know what was intended rather than just what was
written.
Big fan of the Obfuscated C contest?
Again, if parentheses are needed to make an expression readable, then
the expression is either too complex to begin with, or the person
reading it doesn't know the language (and I count knowing at least a
summary of the precedence rules as part of "knowing" the language).
Just as knowing how to read algebraic equations implies knowing the
rules of precedence for mathematical operations (i.e. there is nothing
ambigous about "y = 2x^2 + 3", we know that the exponent comes first,
then the multiplication, and then the addition), knowing how to
read/write C (or C++ or Java, etc.) implies knowing the rules of
precedence for it's operations.
It's a question of intention. If you write 'x+y*w' I know how it will
evaluate, but I'm not sure what's intended. 'x+(y*w)' or '(x+y)*z' make
the intention obvious.
Just like the strange assignment tricks 'if (0==x)' instead of 'if
(x==0)', or the annoying habit of adding comments to perfectly legal
code.
Karl
--
A PBS mind in an MTV world.
Homepage:
http://homepage.mac.com/khsu/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
- Follow-Ups:
- Re: C
- From: Clark Cox <email@hidden>
References: | |
| >Re: C (From: Clark Cox <email@hidden>) |