Program calling unwanted functions

Dave Angel davea at davea.name
Mon Dec 22 18:57:06 EST 2014


On 12/22/2014 06:48 PM, Ian Kelly wrote:
> On Dec 22, 2014 2:37 PM, "Dave Angel" <davea at davea.name> wrote:
>>
>> I'll pick on one function first, called instructions().  If the user
> types something invalid, you print "Invalid input." and call the function
> again.  In this case, because the call is at the end, no harm is usually
> done, but it would be tricky to explain why.  If the user happened to type
> the wrong input 1000 times, you'd hit a recursion limit and crash, but
> that's unlikely unless you have a very stubborn user.
>
> Point of interest, Python (or at least CPython) doesn't optimize tail-call
> recursion, so in fact this sort of unbounded recursion (a "stack leak", if
> you will) is equally bad no matter where it appears in the function.
>

Which is exactly why I mentioned the recursion limit of about 1000.


-- 
DaveA



More information about the Python-list mailing list