Article View: comp.lang.c.moderated
Article #2028Re: Bad Style Contest - We Have a Winner!
From: Konrad Schwarz
Date: Fri, 16 Feb 1996 15:26
Date: Fri, 16 Feb 1996 15:26
75 lines
2719 bytes
2719 bytes
In article <4fjmdt$og4@solutions.solon.com>,
Lawrence Kirby <fred@genesis.demon.co.uk> comments a posting of mine:
|>
|> > since the top level expression (lit == expr) can be identified
|> > immediately.
|>
|> It depends on what is key to the expression. The top level operands can
|> be identified easily enough whether the operator is near the left or right
|> of the expression.
|>
I don't think this is true in the general case. Perhaps I can nudge you in my
direction with an example:
if (-1 == (fd = some_unix_system_call (with, at + least,
three * parameters)))
error_exit (fmt, ...);
I find this more legible than
if ((fd = some_unix_system_call (with, at + least,
three * parameters)) == -1)
error_exit (fmt, ...);
because the parts that belong together---the comparision of -1 with
the result of the system call, i.e., semantically, ``system call failure
check''---are (lexically) close together.
Also:
When writing according to method 1,
I don't get bogged down in the paramters of the system
call until after I have written the check. To elaborate:
By writing the check first, I mentally ``clear the decks''
for the ``hard work'' of finding the correct parameters for the call.
The second method necessitates having to remember ``don't forget the check''
in the back of your head when you are looking for the right arguments for
the call, and then, after doing the ``hard work,'' when your brain would
like to take a breather, remembering to include the check.
(Maybe I'm overstating the case here a bit, but my brain seems to work
this way.)
Finally:
In some sense, error checking has top priority in the first method;
it is almost an afterthought in the second.
|>
|> That isn't necessary. The eye/brain parses expression in logical groups,
|> not simply left to right. That's why layout is important.
|>
I think visual grouping is important too. See above.
[...]
|> if (p = malloc(...)) {
|>
|> would result in a warning whereas:
|>
|> if ((p = malloc(...))) {
|> or
|> if ((p = malloc(...)) != NULL) {
Yes, but I don't write
x + 0
or
y * 1
or (in Pascal)
if z = true then
or
((1))
so something must be wrong.
Konrad Schwarz
Technical Details
Message-ID:
<4g27nn$qaj@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4fjmdt$og4@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: schwarz@a3.complang.tuwien.ac.at (Konrad Schwarz) Newsgroups: comp.lang.c.moderated Subject: Re: Bad Style Contest - We Have a Winner! Date: 16 Feb 1996 09:26:47 -0600 Organization: TU Wien Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4g27nn$qaj@solutions.solon.com> References: <4fjmdt$og4@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com