[Python-ideas] Where-statement (Proposal for function expressions)

Mike Meyer mwm-keyword-python.b4bdba at mired.org
Sat Jul 18 05:58:45 CEST 2009


On Sat, 18 Jul 2009 15:33:59 +1200
Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Steven D'Aprano wrote:
> 
> > But the where clause introduces *look-ahead* to the process:
> > 
> > def parrot():
> >     x = 1
> >     result = x+y+z where:  # look-ahead
> >         y = 2
> >         z = 3
> >     return result
> 
> I think this example is too rarified to give much idea of
> how readable a where-statement might be. 

I, on the other hand, am convinced that this example is dead on. By
requiring the definition to be contextually close to the use, you'll
encourage people to use shorter, less meaningful names. Or can you
honestly say that you use names of the same length and carrying as
much meaning for local variables as you do for globals, attributes and
parameters?

> In real life you wouldn't use arbitrary names like x, y, z. You'd
> choose something to make the expression meaningful in its own right,
> so you can get the gist of what's going on just from reading the
> first line.

What where you're pointing your pronouns! I know you don't speak for
me, and I'm pretty sure you don't speak for Steven (but I don't
either, and he may agree with you).

I'd considered where to be promising, assuming that the problems it
has could be worked through. But Steven's observations are deadly. Not
that the original impulse wasn't good - trying to find things that
scratch the itches that cause repeated "function definition in an
expression" proposals is almost certainly worthwhile.

    <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the Python-ideas mailing list