cond. op. on ='s LHS

Wayne Throop throopw at sheol.UUCP
Mon Feb 18 13:51:48 AEST 1991


> brnstnd at kramden.acf.nyu.edu (Dan Bernstein)
> I'd write [..multi-line if statements instead of
>              cryptic one-liners involving ?: ..]

So would I, 99 and 44 one-hundreths percent of the time.

And the remaining .56 percent of the time wouldn't be for reasons
of "efficency" or to "get close to the machine" or any such secondary
goal.  As Dan points out, such things are unlikely to win over the
good ol' if-then-else.

And yet...  every now and then, one naturally thinks of a situation as
assigning (or incrementing, or tweaking, or whatever) "the appropriate
one of" a set of lvalues.  Now, most often this is modeled as assignment
to an array.  But every once in a blue moon, the lvalues are not related
by membership in an array, nor by anything much in particular beyond
their participation in being one of the set of "appropriate ones" to
assign something to. 

In such a rare case, I'd 'druther code the way I think about it,
and think about it the way I code it.... that is, I'd really rather
model it as a single assignment to a peculiar lvalue.

So while I tend to agree that ?: in lhs expressions are, as a
statistical tendency, an abomination, I can't agree that this
is because of anything wrong with the idea in itself... just
that the application's rightful place is very rare.

The moral is (again): code like you think, think like you code.
( I hope this moral is thought provoking but essentially
  uncontroversial, but one never knows...  )
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org



More information about the Comp.lang.c mailing list