A recursive "loop" is effected by using a function (let's call it "myFunc") which has two return points, one which calls itself and digs deeper (eg "return myFunc(some, modified, args)") and the other which unwinds the digging and returns (eg. "return (value)").
Thus if calling myFunc many times (via the first return point of the func) One incurs the cost of setting up the local variables and storing the return point on the return stack. When the func unwinds it then must deallocate the local stack back to the system. Simple iterative looping does not have this overhead. Python, being a high- level interpreted language, probably has considerable overhead for setting up the local stack for a func to run (compared to something like C). Unwinding recursive loops into iterative loops always aids performance. The (only) reason to use recursion is to express an algorithm in the most elegant terms. For example, consider an algorithm which is defined in recursive terms like the Fibonacci series. Using recursion to determine the nth Fibonacci number is quite natural. However, coding loops into recursion for no other reason than, the language doesn't have iterative loops, or simply because you CAN do it, is an exercise in obfuscation. Oh, another issue to watch out for when looping recursively is that a return address gets pushed onto the return stack for every loop iteration. If you loop one too many times and blow your stack (overrun the stack) you have just borked your system. While your mileage may vary, from a BSOD to a nasty worded MessageBox from the OS, still, it is definitely something which "is NOT a good thing." -- my 3 cents. Rb. On Jul 10, 2:19 pm, eric cs <[email protected]> wrote: > They compare Ruby 1.9 with Python, than a Python guy change the > algorithm from being recursive to being iterative and runs way > faster...wow. > > Can you guys explain those ways of programming with simple examples > with comments? > I heard is very used on functional programming (Erlang,Scala). > How to iterative program in Python and Web2py? > > http://antoniocangiano.com/2007/11/28/holy-shmoly-ruby-19-smokes-pyth... > > http://www.mysoftparade.com/blog/ruby-19-doesnt-smoke-python-away/ > > Thanks. > > more:http://en.wikipedia.org/wiki/Iteration --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

