Design thought for callbacks
Chris Angelico
rosuav at gmail.com
Sun Feb 22 05:21:17 EST 2015
On Sun, Feb 22, 2015 at 8:14 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Helping it along means your program doesn't waste memory. Why such a
>> blanket statement?
>
> Because worrying Python programmers with evil spirits (reference loops)
> leads to awkward coding practices and takes away one of the main
> advantages of Python as a high-level programming language.
Right, and I suppose that, by extension, we should assume that the
Python interpreter can optimize this?
def fib(x):
if x<2: return x
return fib(x-2)+fib(x-1)
Just because a computer can, in theory, recognize that this is a pure
function, doesn't mean that we can and should depend on that. If you
want this to be optimized, you either fix your algorithm or explicitly
memoize the function - you don't assume that Python can do it for you.
Even when you write in a high level language, you need to understand
how computers work.
ChrisA
More information about the Python-list
mailing list