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

Chris Mellon arkanes at
Thu Jul 31 19:27:41 CEST 2008

On Tue, Jul 29, 2008 at 3:37 AM, Carl Banks <pavlovevidence at> wrote:
> On Jul 28, 8:15 pm, Steven D'Aprano <st... at REMOVE-THIS-
>> wrote:
>> On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote:
>> > On Jul 28, 10:00 am, Steven D'Aprano <st... at REMOVE-THIS-
>> >> wrote:
>> >> Cutting to the crux of the discussion...
>> >> On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote:
>> >> > I want something where "if x" will do but a simple explicit test
>> >> > won't.
>> >> Explicit tests aren't simple unless you know what type x is. If x could
>> >> be of any type, you can't write a simple test. Does x have a length? Is
>> >> it a number? Maybe it's a fixed-length circular length, and the length
>> >> is non-zero even when it's empty? Who knows? How many cases do you need
>> >> to consider?
>> > Use case, please.  I'm asking for code, not arguments.  Please give me a
>> > piece of code where you can write "if x" that works but a simple
>> > explicit test won't.
>> I gave you a piece of code, actual code from one of my own projects. If
>> you wouldn't accept that evidence then, why would you accept it now?
> I would accept as "evidence" something that satisfies my criteria,
> which your example did not: it could have easily (and more robustly)
> been written with a simple explicit test.  I am looking for one that
> can't.
> You keep bringing up this notion of "more complex with no benefit",
> which I'm simply not interested in talking about that at this time,
> and I won't respond to any of your points.  I am seeking the answer to
> one question: whether "if x" can usefully do something a simple
> explicit test can't.  Everyone already knows that "if x" requires
> fewer keystrokes and parses to fewer nodes.

I'm really not sure where you're going with this or what you're trying
to prove. "if x" is a duck-type test for a boolean value. Obviously if
you know the type and want a more *specific* test, then you can use an
explicit one. Any time you don't know or don't care about a more
specific type than "something which probably is boolean true", or any
time where you know the boolean semantics of the type and want to drop
some typing, you can use "if x". The more specific test is what you'd
use if you want more specific results. What's complicated about this

More information about the Python-list mailing list