Fibonacci series recursion error

Hans Georg Schaathun hg at schaathun.net
Mon May 2 09:14:20 EDT 2011


On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy
  <tjreedy at udel.edu> wrote:
:  This does not make linear recursion 'bad', just impractical for general 
:  use on finite-memory machines. While I consider it very useful for 
:  learning, it is unnecessary because it is easy to write an iterative 
:  version. So called tail-recursion optimization saves memory by REMOVING 
:  RECURSION and replacing it with iteration.
: (...)
:  Python does not do this automatically because 1) it can be a semantic 
:  change under some circumstances; 2) one who wants the iterative version 
:  can just as easily write it directly;

That's the silliest argument I ever heard.  The programmer should write
the code the way he and application domain experts think, i.e. very
often recursively.  The compiler should generate code the way the CPU
thinks (most optimally), i.e. iteratively.

Of course, I am not saying that one should always model problems
recursively, and thus also not that one should implement them
recursively.  Just that when a model is agreed recursively between
the stakeholders, one should get a compiler to do the optimisation,
not a programmer.

I always thought of python as a step forward, in the way it allows 
direct expression of so many alternative modes of thinking (imperative,
functional, recursion, iterators, etc).  If what you say is python
philosophy, it is a step backward in requiring the programmer to
think more about low-level technical matters which even C has managed
to leave for the compiler.

:        and 3) Python has a better way to 
:  process collections that removes essentially all the boilerplate in the 
:  recursive-call and while-loop versions:


-- 
:-- Hans Georg



More information about the Python-list mailing list