[Python-Dev] Informal educator feedback on PEP 572 (was Re: 2018 Python Language Summit coverage, last part)

Steven D'Aprano steve at pearwood.info
Tue Jun 26 21:42:19 EDT 2018

On Mon, Jun 25, 2018 at 11:30:24AM +1200, Greg Ewing wrote:
> Guido van Rossum wrote:
> >Greg seem to be +0 or better for (a)
> Actually, I'm closer to -1 on (a) as well. I don't like := as a
> way of getting assignment in an expression. The only thing I would
> give a non-negative rating is some form of "where" or "given".
> Brief summary of reasons for disliking ":=":
> * Cryptic use of punctuation

":=" is the second most common syntax used for assignment in common 
programming languages, not just Pascal. Even modern languages like Go 
use it. If that's "cryptic", what word would you use to describe 
@decorator syntax? *wink*

Honestly Greg, can you put your hand on your heart and swear that if you 
came across "name := expression" in source code you wouldn't be able to 
hazard a guess as the meaning of the := operator?

> * Too much overlap in functionality with "="

If you are willing to consider a non-negative rating under the 
"given/willing"spelling, presumably the "overlap in functionality" isn't 
that important. (Otherwise it would be an argument against the feature 
*regardless of spelling*.)

So why should it be an argument against the := spelling?

> * Asymmetry between first and subsequent uses of the bound value

I don't know what this means.

> * Makes expressions cluttered and hard to read to my eyes

And Nick's more verbose "given" proposal makes expressions less 

result = process(first=(spam := ham or eggs), second=spam*5)

result = process(first=(spam given spam = ham or eggs), second=spam*5)

The := spelling has three syntactic elements: the target name, the := 
operator itself, and the expression being assigned.

The syntax you are willing to consider has five elements: an arbitrarily 
complex return expression, the keyword "given", the target name, the = 
operator, and the expression being assigned.

It isn't rational to say that adding extra complexity and more syntactic 
elements *reduces* clutter. At the minimum, Nick's syntax requires:

- an extra keyword ("given" or "where")

- a repetitive, redundant, repeated use of the target name

just to save one : character. That adds, not subtracts, clutter.

Aside from the asymmetry issue (which I don't understand) it seems that 
most of your arguments against := apply equally, or even more strongly, 
to the "expr given name = expr" version.

I know matters of taste are deeply subjective, but we ought to 
distinguish between *subjective* and *irrational* reasons for disliking 
proposed features, and try to resist the irrational ones:

    "We should change the spelling of set.add to set.append, as
    that will remove the troublesome double-letter, and reduce



More information about the Python-Dev mailing list