Fibonacci series recursion error

Paul Rudin paul.nospam at
Sat Apr 30 01:43:42 EDT 2011

harrismh777 <harrismh777 at> writes:

> lalit wrote:
>> The above function return the
>> return (fib(n-1)+fib(n-2))
>> RuntimeError: maximum recursion depth exceeded in comparison
>> [36355 refs]
> There is much debate about this generally, but general wisdom is that
> recursion is to be avoided when possible. Another way to say this is,
> "Only use recursion when there is no other obvious way to handle the
> problem".
> Recursion is very tempting to young artists because its a ~cool trick,
> and because sometimes it requires very little coding (although huge
> amounts of memory!),  

Writing recurive code is acceptable and is a nice clear way of
expressing things when you have naturally recursive data structures, and
can lead to perfectly good compiled code. The problem in CPython is the
lack of tail optimization, so it's not a good idea for python . Some
language standards guarantee tail optimization...

More information about the Python-list mailing list