Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Nov 26 16:48:46 EST 2015


BartC wrote:
> I simply stated that Python's approach was novel. Steven D'Aprano then 
> responded by belittling my view, and effectively trashing every language 
> I've ever used.

He pointed out that many other dynamic languages construct
functions on the fly the same way that Python does, going
all the way back to the earliest Lisp implementations. If
you think that Python invented that idea, then either you
haven't studied any of those languages, or you didn't
realise that's what they were doing. If your view was
"belittled" in any way, it's only because you said something
that is objectively wrong.

> But as it happens I do think features like first class functions are 
> overrated (and probably the software underpinning the hardware we're all 
> using is written in the very languages he despises). I don't think a 
> language is worthless without such a feature.

I think Steven went off on a bit of a tangent there.
First-classness of functions doesn't really have anything
to do with whether they're constructed statically or
dynamically. C lets you pass pointers to functions around,
for example, but I don't think anyone would describe C
as executing function definitions at run time.

While a language isn't worthless without first-class
functions, such a language tends to feel rather limited
if you're used to having them. Think of any API that
involves passing in callback functions, and what you
would have to do if you didn't have that ability.

Anyhow, the whole issue of static vs. dynamic function
creation is itself tangential to what started all this.
I think Laura Creighton has it right: Python provides
exactly *one* way to delay evaluation of code: put it
in the body of a function. That's a very simple rule,
and I think maintaining that simplicity is a good
thing.

-- 
Greg



More information about the Python-list mailing list