[Python-ideas] Ruby-style Blocks in Python Idea

Guido van Rossum guido at python.org
Mon Mar 9 21:29:16 CET 2009


On Mon, Mar 9, 2009 at 1:22 PM, average <dreamingforward at gmail.com> wrote:
> What's misleading about framing this discussion is that all of us are
> [over]used to the "flatland" of the program editor.  Code blocks
> appear on the screen like any other code, but the *critical* point is
> that LOGICALLY they are ORTHOGONAL to it.  Where most of your code
> could be organized in a tree-like fashion rooted in your program's
> "main" node, code blocks are orthogonal and are really like leaves
> spanning back into the screen to a *different* tree's root (the
> *application's* surface) hence its subtlety.

That's only one use of callbacks. One could claim that a confusing
part of anonymous blocks (as used in SmallTalk and Ruby) is that they
use the same syntax for both use cases: you can't tell from the syntax
whether the block is executed in the place where you see it (perhaps
in a loop or with an error handler wrapped around it, or conditionally
like in SmallTalk's "if" construct), or squirreled away for later use
(once or many times).

The good thing about function syntax (as used in JavaScript's
anonymous blocks) is that it leaves no doubt about these two different
uses: at least by convention, anonymous functions are used for
asynchronous programming, while in-line code uses regular block
syntax.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list