[Python-ideas] Where-statement (Proposal for function expressions)
greg.ewing at canterbury.ac.nz
Sat Jul 18 06:20:43 CEST 2009
> Steven D'Aprano wrote:
> > In a real sense, the proposed 'where' block breaks the flow of reading
> > code. Normally, reading a function proceeds in an orderly fashion from
> > the start of the function to the end in (mostly) sequential order, a
> > bottom-up process:
Here you're assuming that the order of *execution* of the
code is necessarily the best order for *reading* it in
order to understand what it does.
In general I think that's mostly false. When encountering
a program for the first time, one tends to look for the
"main" function first, to get an overall idea of what's
being done, then recursively work one's way down into lower
Python supports this on a large scale by allowing functions
and classes to be written pretty much in any order,
regardless of the order of execution.
There's not much support for it on a small scale, though.
There is a little. List comprehensions are one example,
where you get to see the high-level intent first -- make
a list of stuff -- and then you're shown the lower-level
Another one that's easy to overlook is the assignment
statement. Nobody seems to be bothered by the fact that
the *right* hand side has to be evaluated before assigning
to the left hand side.
In a sense, the where-block is in part an attempt to extend
the assignment statement so that the "right hand side" can
span more than one statement.
More information about the Python-ideas