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

Carl Banks pavlovevidence at gmail.com
Thu Jul 31 22:36:48 EDT 2008


On Jul 31, 1:27 pm, "Chris Mellon" <arka... at gmail.com> wrote:
> 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
> idea?

Many people trumpet that "if x" makes your code more polymorphic
whenever this comes up--in fact you just repeated the claim--without
ever considering how rarely this more extensive polymorphism comes up
in practice.   I was calling them out to say "prove to me that it
actually happens".

I believe it's very rare not to know enough about the expected type
that explicit tests won't work.  We've uncovered a few examples of it
in this thread, but IMO we haven't uncovered any sort of broad, wide-
ranging use cases.


Carl Banks



More information about the Python-list mailing list