[Python-ideas] If branch merging

Andrew Barnert abarnert at yahoo.com
Mon Jun 8 15:21:40 CEST 2015


On Jun 8, 2015, at 05:26, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 
> The problem with a let expression is that you still end up having to
> jumble up the order of things, just as you do with the trick of
> defining and calling a function, rather than being able to just name
> the subexpression on first execution and refer back to it by name
> later rather than repeating the calculation.

But notice that in two of your three use cases--and, significantly, the ones that are expressions--the place of first execution comes lexically _after_ the reference, so in normal reading order, you're referring _forward_ to it by name. 

He can front a clause without swapping the pronoun and its referent if Nick intends that special emphasis, but otherwise he wouldn't do that in English. That's a valid English sentence, but you have to think for a second to parse it, and then think again to guess what the odd emphasis is supposed to connote.

Sometimes you actually do want that odd emphasis (it seems like a major point of your given proposal), but that's not the case here. It's the temporary name "b" that's unimportant, not its definition; the only reason you need the name at all is to avoid evaluating "a.b" twice. So having it come halfway through the expression is a little weird.

Of course the same thing does happen in comprehensions, but (a) those are one of the few things in Python that are intended to read as much like math as like English, and (b) it almost always _is_ the expression rather than the loop variable that's the interesting part of a comprehension; that isn't generally true for a conditional.


More information about the Python-ideas mailing list