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

Guido van Rossum guido at python.org
Mon Mar 9 18:26:14 CET 2009


On Mon, Mar 9, 2009 at 10:15 AM, tav <tav at espians.com> wrote:
>> Can you explain why:
>>   func(named_function)
>> is radically different from:
>>   func(multi-line-code-block-without-the-name)
>
> Hmz, the intention isn't to support multi-line lambdas. It's to make
> passing in anonymous functions easier.

Well, that works only as long as there is only a single anonymous
function to pass in and it's the last argument. Plus it doesn't work
with an existing function that takes a function argument -- your
function (if I understand your proposed __do__ implemtation correctly)
must really be a generator.

> For precedence let's take a look at decorators. Fundamentally,
> decorators save a user nothing more than a single line of code.

I guess you weren't there at the time. If it was about saving a line
of code it would have been boohed out of the room. (Especially since
the line count is actually the same with or without using the
decorator syntax!) The big improvement that decorators offer is to
move the "decoration" from the end of the function body, where it is
easily missed, to the front of the declaration, where it changes the
emphasis for the reader. I don't see a similar advantage in your
example; it looks more like "Ruby-envy" to me.

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



More information about the Python-ideas mailing list