[Tutor] Re: Are you allowed to shoot camels? [kinda OT]

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Fri Feb 4 20:00:15 CET 2005

Alan Gauld wrote:
>>>foo = x and y or z
>>>is much less elegant than
>>>foo = x ? y : z
>>You must be joking too... You think that
>>x and y or z
>>is as clear as
>>x ? y : z
> I think its clearer! It says that the first two things happen
> or else the last thing. Plain English.

That's apparently subjective then. I know what it means because I've 
read about it, but I still have trouble really grokking it. I don't have 
any problem with 'x and y' or with 'x or y', but somehow the combination 
of the two is one step too many for me.

> '?:' means absolutely nothing without somebody to explain it.

But ever since it was explained to me, I can parse it in the blink of an 
eye. (x**2 for x in range(10)) didn't mean anything to me either, the 
first time I saw it.

> Interesting, obviously a lot of support for both, yet they are
> features I try to avoid in C(*) and never miss in Python. If
> given the choice I'd much rather have decent lambdas or
> even a repeat/until loop!

I don't really try to avoid them; I just use them when appropriate, 
which is not very often. But in those rare cases, I'm glad I don't have 
to resort to other, less appropriate constructs.

And yes, a decent lambda would be nice indeed. Repeat/until too: I used 
it quite a lot in my Pascal days. But I don't know if it's worth 
cluttering the language up for.

> (*)And most software houses I've worked with have ternary
> operators on their "do not use" list along with switch fall-throughs.

In my experience, such lists often go too far in that respect. I agree 
that fall-trough should mostly be avoided (except when multiple values 
should leed to the same branch). Ternary operators can certainly be 
abused (as demonstrated by much of the IOCCC entries), but can 
absolutely be useful when judisciously used. Many such lists seem to 
assume that developers can't judge such things for themselves. I think 
that if you have developers that can't do that, you have worse problems 
than a ternary operator here and there.

"Codito ergo sum"
Roel Schroeven

More information about the Tutor mailing list