[Tutor] recursive problem

Luke Paireepinart rabidpoobear at gmail.com
Sat Sep 11 19:51:54 CEST 2010


On Sep 11, 2010, at 12:40 PM, Roelof Wobben <rwobben at hotmail.com> wrote:

> 
> 
> 
> ----------------------------------------
>> From: steve at pearwood.info
>> To: tutor at python.org
>> Date: Sun, 12 Sep 2010 03:27:42 +1000
>> Subject: Re: [Tutor] recursive problem
>> 
>> On Sun, 12 Sep 2010 03:18:19 am Steven D'Aprano wrote:
>> 
>>> But that hasn't done anything to prevent race conditions. So the real
>>> reason people use LBYL is that they're too lazy to write hideously
>>> ugly, but reliable, code, and they're just hoping that they will
>>> never expose the race condition. (Often this is a pretty safe hope,
>>> but not always.)
>> 
>> http://en.wikipedia.org/wiki/Ostrich_algorithm
>> 
>> 
>> --
>> Steven D'Aprano
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
> 
> Oke,
> 
> But why is type checking then wrong.
> Lets says I want a module who must work on strings, tuple and lists.
> 
> Can I then use EAFP ?
> 
> Without type checking I never know which one is used now.
> 
> Roelof
>                           

That's the whole point! You don't WANT to know what type it is. You want to just use it how you want, an if it behaves properly, who cares what type it is?

See when you type check you are forcing the user to use those types. What if they want to derive a subclass from list? Is there really a reason why you should prevent them from using that subclass with your function?
If there is a valid reason, type checking is fine. But if there isn't, type checking is just making your code more inflexible.



More information about the Tutor mailing list