Boolean tests [was Re: Attack a sacred Python Cow]
Erik Max Francis
max at alcyone.com
Wed Jul 30 08:06:32 CEST 2008
Carl Banks wrote:
> Bull. This is a request, that, if satisfied, would prove that "if x"
> is more polymorphic than a simple explicit test. I posed the question
> precisely to see if anyone could come up with a use case that shows
> this benefit of "if x".
Except you're the only one who's not convinced of it, and it's your
test, and your rules. So who cares?
>> "if x" _is_ a completely simple
>> test. Simpler, in fact, than the ones you were advocating.
> It's not explicit.
It's not explicit enough for you, yes, that much is obvious. Contests
that rely on mind-reading aren't too much fun for anyone involved.
> I've explained why I doubt that it helps polymorphism that much: you
> almost never see code for which an integer and list both work, so
> having the ability to spell a test the same way for both types isn't
> useful. If you claim that "if x" does help polymorphism, please tell
> me what's wrong with the above analysis.
It helps polymorphism for types other that (say) numerics and sequences.
There are plenty of container objects for which an "is this
non-empty?" test is far simpler a "how many objects are in this
container?" test, and several examples have already been given -- as in,
O(1) vs. O(n) complexity or worse. You've seem to have even
acknowledged this, but are still insisting on continuing the challenge.
You're drawing an artificial line in the sand to compare length
computation to a more specialized non-emptiness test. (And, as I've
pointed out, what happens if you're dealing with a sequence type that
_doesn't_ have a length? Then certainly `len(x) != 0` is nonsensical.)
Perhaps in the particular use case you're thinking of (numeric types vs.
container types), there aren't any good examples. But who cares?
Polymorphism applies in more than just this one special case. You're
setting up a challenge that isn't very interesting, and which is rigged
so that no one can win because you're the one who. So, what's the point?
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
Can I be your friend / 'Till the end
-- India Arie
More information about the Python-list