From: Hans Georg Schaathun Newsgroups: comp.lang.python Subject: Re: Fibonacci series recursion error Date: Mon, 2 May 2011 14:14:20 +0100 Organization: University of Bergen Lines: 37 Message-ID: References: <87iptw1egh.fsf@rudin.co.uk> <87ei4k0ygz.fsf@rudin.co.uk> <87aaf7246f.fsf@rudin.co.uk> <4dbd221a$0$29991$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: vannskorpion.bccs.uib.no X-Trace: toralf.uib.no 1304343842 90789 129.177.20.20 (2 May 2011 13:44:02 GMT) X-Complaints-To: abuse@uib.no NNTP-Posting-Date: 2 May 2011 13:44:02 GMT User-Agent: slrn/pre1.0.0-18 (Linux) Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!uio.no!nntp.uib.no!svn.schaathun.net!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4480 On Sun, 01 May 2011 18:24:30 -0400, Terry Reedy 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