Farm Development

Python gets true closures in 3000 - do I care?

Really the only thing stopping python 2.x from having closures like how Martin Fowler defines them is that, aside from the global module space, you can't re-bind names in enclosed scopes; you can only have a local reference. An *ahem* unnamed coworker of mine who mainly uses Ruby seems to enjoy pointing this out. I actually like how you only get local refs in python; it seems safer. (As an aside I think Rite, Ruby2, is deprecating non-local refs by default but maybe that has changed.)

Python 3000 will solve this problem once and for all with the nonlocal keyword. Rejoice? I guess so. The PEP demonstrates the current workaround, a class they call Namespace, which—in the rare case that it's necessary—is how I do it and that never bothered me ... but doing without a workaround will certainly be nice.

I should also note that Python 2.5 added the with statement which provides a nice shortcut for transactional closures. This was spawned, I think, from a request to add ruby-style blocks to python.

  • Re: Python gets true closures in 3000 - do I care?

    "a request to add ruby-style blocks to python"

    If you think the world began when Ruby was first released, you need to read some more computer language history ;-)

    (better support for anonymous blocks in Python has been discussed since long before "lambda" was first added to Python in 1994. and other languages had them long before that, of course.)

  • Re: Python gets true closures in 3000 - do I care?

    I don't know much about ruby aside from when I read a book about it. At the end, I decided there were no benefits in it for me over python.

Note: HTML tags will be stripped. Hit enter twice for a new paragraph.

Recent Projects

  • JSTestNet

    Like botnet but for JS tests in CI.

  • Nose Nicedots

    Nose plugin that prints nicer dots.

  • Fudge

    Mock objects for testing.

  • Fixture

    Loading and referencing test data.

  • NoseJS

    Nose plugin that runs JavaScript tests for a Python project.

  • Wikir

    converts reST to various Wiki formats.