Self function

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon May 4 14:26:25 EDT 2009


Steve Howell:
>two methods with almost identical names, where one function is the public interface and then another method that does most of the recursion.<

Thanks Guido & Walter both Python and D support nested functions, so
in such situations I put the recursive function inside the "public
interface" function/method.

Recursion is a high-level way to represent certain kinds of algorithms
in a short and readable way (when data structures are nested, the most
natural algorithms that work on them are recursive). But in Python
function calls are slow, the maximum level of nested calls is limited
(and it can't grow too much), so this has sometimes forced me to
manually convert recursive functions into iterative ones with a stack.
This is silly for a supposed high-level language. The bad support for
recursivity is one of the few faults of Python.

Bye,
bearophile



More information about the Python-list mailing list