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

Antoon Pardon apardon at forel.vub.ac.be
Fri Aug 1 15:30:32 CEST 2008


On 2008-08-01, Matthew Fitzgibbons <elessar at nienna.org> wrote:
> Antoon Pardon wrote:
>> On 2008-08-01, Erik Max Francis <max at alcyone.com> wrote:
>>> Antoon Pardon wrote:
>>>
>>>> I now have the following question for people who argue that "if x"
>>>> is more polymorphic. I could subclass list, so that instances
>>>> of this new sequence would always behave as true, even if they are
>>>> empty.  I could then rewrite my loop as follows:
>>>>
>>>> while 1:
>>>>   extra = produce()
>>>>   if not extra:
>>>>     break
>>>>   for el in extra:
>>>>     adjust_with(el)
>>>>   calculate()
>>>>
>>>> Is this second loop now more polymorphic as the first?
>>> It's more confusing since you've changed the standard behavior of a 
>>> standard type, which doesn't really have anything to do with 
>>> polymorphism.  It's more confusing, if that's a benefit.
>> 
>> So you accept my point that "if x" can be less polymorphic
>> and in fact can be more confusing than a more specific test.
>> 
>
> I think your example is more related to a trap with polymorphism in 
> general rather than an argument against 'is x' specifically.

I didn't want to argue against "if x". I just wanted to give a
counter point to the argument that "if x" is more polymorphic.

Whether more or less polymorphic is good or bad, depends on
what kind of polymophism and circumstances.

-- 
Antoon Pardon



More information about the Python-list mailing list