Boolean tests [was Re: Attack a sacred Python Cow]

Ethan Furman ethan at
Thu Jul 31 06:13:07 CEST 2008

Carl Banks wrote:
> On Jul 30, 4:49 am, Ethan Furman <et... at> wrote:
>> Even for those that did realize, and in fact hoped that that is what you
>> were attempting to accomplish,
> I was not attempting to accomplish what you think I was.
> I was looking for it, but I didn't want to see it.  I didn't expect to
> see it.  I wanted to show that "if x" doesn't have the polymorphic
> advantage people mindlessly claim it does by posing the challenge and
> having people fail to meet it, and for the most part the examples that
> met the challenge were for minor usages.  Ok, someone wrote a filter
> that truly benefits from polymorphism of "if x" against very different
> types, but really, these use cases aren't all that common.
> It's not like it's an everyday thing for you to write "if x" instead
> of "if x!=0", and that it actually saves you from having to rewrite
> the condition because later you decided to use a list.

Actually, I use this construction a lot.  But everybody has their own 
style, and I'm certainly not going to tell you yours is wrong.  One of 
the fellows that works for me *loves* the (result if false, result if 
true)[condition] style of immediate if's -- it's one of the first things 
he learned about when studying Python, and he grins every time he talks 
about it; *I* know it's not the best way to do it, and that it has it's 
own set of gotchas -- so I made sure he was also aware of them, and uses 
them where and when they won't blow up in our faces.

> So I stand by the point I was trying to make: for your average day-to-
> day programming, the main benefit of "if x" is to save keystrokes.  It
> doesn't help your code become more polymophic in practice.  A little
> more polymorphic, yes.  A lot, no.


> Carl Banks

Hmmm... well, I see your point.  Unfortunately, even though it feels 
incorrect to me, I do not (yet) have the breadth and depth of Python 
experience to come up with an example that would display such exquisite 
polymorphism.  It also seems to me that such an example would be 
non-trivial in nature.  Perhaps starting a new thread with this 
challenge, and adequate time (couple weeks at least, I would think) 
would net you the smoking gun you were after.

At any rate, from my point of view, I like it.  I like the visual 
clarity and simplistic nature of "if x" -- it tells me "if x is 
something", and I trust myself enough to know what I can do with the 
something that is x.  I also expect anyone else passing me a something 
to know it has the appropriate interface to work with my code.


More information about the Python-list mailing list