A question of style
Andrew P. Mullhaupt
amull at Morgan.COM
Tue Dec 5 13:37:11 AEST 1989
In article <1989Dec4.032918.16550 at twwells.com>, bill at twwells.com (T. William Wells) writes:
> In article <565 at s5.Morgan.COM> amull at Morgan.COM (Andrew P. Mullhaupt)
> [presents his subjective judgements as relevant to the discussion.]
I doubt it is possible to discuss questions of style with complete
objectivty, but I do not believe that nothing constructive can be said.
My 'readability ethic' is perhaps evident in the analogy between
reading a newspaper and reading a program; activities which shouldn't
be as far apart as they presently seem. Journalists and newspaper
editors live and die by achieving the widest possible readability,
(as well as by advertising gimmicks...) and perhaps we might profit
by thinking about how this comes about. Try substituting the words
'C program' for 'newspaper', 'statement' for 'sentence', and
'preprocessing' for 'typesetting' in the following:
When you read a newspaper, there's something dreadfully wrong
if your first impression is of cleverly and compactly punctuated
sentences with new and interesting typesetting. The punctuation and
typesetting are important, but only so far as they are needed to
determine meaning, and assist the human reader to correctly grasp it.
>
> Sorry buddy, but your judgements are not mine. Moreoever, while
> some of your conclusions are valid, basing them on subjective
> judgements makes them appear less valid.
>
> For example,
>
> "There are no good excuses for the comma operator because
> it masquerades as true concurrent assignment where it is a
> poor relation of it."
>
> Maybe you think that the comma operator looks like concurrent
> assignment. If so, you need to work harder at disentangling your
> previous experience from your C programming. Many, perhaps most,
> C programmers don't ever think of concurrent assignment when
> seeing the comma operator. Certainly experienced C programmers
> don't.
I don't think the standard of readability is wide enough if
only by removing 'previous experience' can we understand C programs.
Also: I disagree. Comma clauses which occur as "re-initializations"
in for constructs are often a form of concurrent assignment. You want
to make more than one assignment in a place where a single statement
is required, because these assignments belong together. Now either
they are sequential (order dependent) in which case the comma clause
will contain side effects, or they are done essentially as concurrent
assignment. Now it really doesn't matter what the programmer thinks
when he writes the code, (most of the RISC architectures had to do away
with the RPM - 'read programmer's mind' instruction), it matters what
is written.
> You then go on to say:
>
> "The thing invites you to cram all sort of gooey side
> effects into for loops with increment and assignment
> operators."
>
> Which is true, yet since you present it as related to that
> subjective statement, you *weaken* the force of the statement.
>
> Then you say (after a gratuitous and false ad hominem):
I didn't mean for my sarcasm to be taken as ad hominem, and so I
must apologise. I was trying to indicate how side effects can obscure
the real intent of a comma expression. I didn't think anyone would
seriously prefer that form.
>
> : Now with real concurrent assignment, you
> : really can put your loop invariant maintenance in one place:
> :
> : (i++ , j--)
> :
> : can be replaced by the much more attractive:
> :
> : (i, j) := (i + 1, j - 1)
>
> Yet again we have a very subjective judgement, one which I very
> much disagree with. In fact, I'd say that the latter is defective
> on more than one level. Besides the extraneous characters needed
> to express a much simpler idea, you have interleaved two distinct
> ideas, incrementing `i' and decrementing 'j'; this sort of thing
> leads to decreased understanding.
>
Finally - the real nitty-gritty:
You can disagree all you want, but there is a reason that the
concurrent assignment is preferable to the comma clause, and it
has nothing to do with counting characters. It has to do with
the putative role of the given expression as establishing a loop
invariant.
When you establish an invariant expression, you would like to
do it all in one place, and all at the same time. Since concurrent
assignment evaluates the right hand side before making any of the
assignments, you are assured that there is no 'sequence point' where
half of your invariant has been fixed (and the other half broken)
and you are relieved of the burden of worrying about what order
the assignments are done in. Not having control of this order stops
all but the most reckless programmers from putting in side effects,
function evaluations, or anything else sticky in the expression.
Later,
Andrew Mullhaupt
More information about the Comp.lang.c
mailing list