A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-April/152920.html below:

[Python-Dev] PEP 572: Assignment Expressions

[Python-Dev] PEP 572: Assignment ExpressionsTim Peters tim.peters at gmail.com
Tue Apr 24 02:06:30 EDT 2018
[Steve Holden <steve at holdenweb.com>]
>> ...
>> The assignment expression seems like a vary natural way to introduce
>> variables of limited (controlled?) scope, [...]

[Antoine Pitrou <solipsis at pitrou.net>]
> AFAIU, the scope isn't limited to the "if" block, it's a regular local
> variable.  I might have misread.

You're right about the current version of the PEP.  No new scoping
rules are introduced.  The PEP does suggest some changes to corner
case scoping semantics, though.


> ...
> Regardless, my three questions about this are:
> - does it make Python more powerful?

Goodness no.


> - does it make Python more readable?

There are cases where it would, and cases where it wouldn't.  People
shouldn't use it in the latter cases ;-)  I very recently wrote this
block of code:

    outside = p2units[p1][tgt_kind] - units[2]
    if outside:
        if not all(self.crossout(q, n, undo)
                     for q in outside):
            return False

The opening pair is a very common minor annoyance; it's marginally
more readable like so:

    if outside := p2units[p1][tgt_kind] - units[2]:

Saving an essentially useless line with a duplicated name is worth
something to me, because it comes up so very often.

But that's indeed "minor".  In my diff/gcd example, it reduced 5 lines
of code to 2; saved a level of annoying (semantically misleading)
indentation; and cut the number of instances of both "diff" and "g"
from 3 each to 2 each (ideal:  one each to bind the name, and then one
each to use the name later).  That's relatively substantial by any
measure.

In Guido's if/elif/elif/elif/elif ... complex text processing example
template, it can save an unbounded number of semantically needless
indentation levels.

So the readability benefits can range from highly negative to highly positive.


> - does it make Python easier to learn and teach?

By whom?  Almost no addition has ever made a language easier to learn
for raw beginners:  every addition is something they eventually need
to learn.  We could make Python easier to learn for beginners by
throwing out virtually everything added since version 0.9.6 ;-)

But people coming _from_ most other very widely used languages (C,
C++, Java, Javascript, Perl, ...) are already familiar with assignment
expressions.  The limited (to a plain identifier target) "binding
expression" PEP simplification I favor would be nothing new to them at
all (whereas the full complexity of Python's assignment statements is
indeed beyond what they're used to, but needs to be taught & learned
regardless of this PEP's fate).

At least when restricted to binding expressions, the syntax is simple
and the semantics are the very simplest case of what people (convert
or raw beginner) need to learn for Python's assignment statements
regardless.


> My answer would be "no" to all three, but YMMV.

And it did ;-)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4