[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Nick Coghlan ncoghlan at gmail.com
Mon Sep 26 15:54:21 CEST 2011

On Mon, Sep 26, 2011 at 8:26 AM, Alex Gaynor <alex.gaynor at gmail.com> wrote:
> You had me, you really did.  Right up until you showed the current equivalent.
> This strikes me as a few things.
> Most importantly, as you noted yourself, a pretty rare case, even in C static
> variables are probably the rarest scope of variable.  This strikes me as a) not
> saving very much code, it's like crappy HFS instead of real sugar ;), and b)
> not adding fundamental value, I think both blocks of code are equally readable.
> Other examples of syntatic sugar, such as decorators, have code motion
> properties  that let you think about code in the places that makes sense, and I
> don't think this has that.

To my mind, a 4:1 reduction in boilerplate lines, moving the function
name out to the top level, making it clear that there's only one
function (the inner one) that is kept around, avoiding repetition of
the variable name and the function name all count as fairly
substantial wins on the 'sugary goodness' front :)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list