|
|
Subscribe / Log in / New account

Discussing PEP 572

By Jake Edge
March 14, 2018

As is often the case, the python-ideas mailing list hosted a discussion about a Python Enhancement Proposal (PEP) recently. In some sense, this particular PEP was created to try to gather together the pros and cons of a feature idea that regularly crops up: statement-local bindings for variable names. But the discussion of the PEP went in enough different directions that it led to calls for an entirely different type of medium in which to have those kinds of discussions.

PEP 572 ("Syntax for Statement-Local Name Bindings") has been through two revisions at this point, with robust discussion of both on python-ideas. The idea is that values with short lifetimes (for the duration of a single statement) may need to be referred to more than once during that lifetime. The canonical example from the PEP is:

    stuff = [ [f(x), f(x)] for x in range(5) ]
That works just fine, but if f() is costly or has side effects, that price will be paid twice in creating the list of lists. PEP 572 proposes new syntax that would allow any Python expression expr to be replaced with (expr as name); it would have the same value as the expression but also bind that value to name. That binding would only last until the end of the statement that contained it. Using that would allow the above example to be written as follows:
    stuff = [ [(f(x) as y), y] for x in range(5) ]

The comments on the first posting went in a bunch of different directions, some of which were anticipated by PEP author Chris Angelico as "open questions" in the PEP. Mostly those questions concerned corner cases of various sorts, such as how to handle the statement-local name bindings (SLNBs) for names that have already been used:

    (x, (1 as x), x)
Should the SLNB x shadow the x in the wider scope? Furthermore, there were questions (and a variety of answers) on what the following code should do:
    b = (3 as b)
The existing prototype implementation creates the SLNB for b before doing the lookup for the assignment; thus it assigns to the statement-local b, which goes out of scope at the end of the statement. So it effectively does nothing—which could easily be confusing.

The list comprehension example given in the PEP is not the truly interesting use case, at least for some participating in the thread. The SLNB is active until the end of the statement, which includes blocks, so the following would also be possible:

    if (re.search(pat, text) as match):
	print("Found:", match.group(0))

    while (sock.read() as data):
	print("Received data:", data)
For those, match and data would go out of scope after the completion of their blocks.

As is fairly normal for discussion on a mailing list, the thread had several lengthy sub-threads with comments (and replies several levels deep) that touched on multiple pieces of the PEP. That did not sit well with Robert Vanden Eynde, who asked: "Isn't it easier to talk on a forum?" As might be guessed, the answer from several was "no", but there was more to it than that. Vanden Eynde said:

We are currently like a dozen of people talking about multiple sections of a single subject.

[...] A forum (or just few "issues" thread on github) is where we could have different thread in parallel, in my messages I end up with like 10 comments not all related, in a forum we could talk about everything and it would still be organized by subjects.

Also, it's more interactive than email on a global list, people can talk to each other in parallel, if I want to answer about a mail that was 10 mail ago, it gets quickly messy.

We could all discuss on a gist or some "Issues" thread on GitHub.

Several participants expanded on their opposition to a forum-style discussion; many have built up a great deal of tooling to handle email, much of which is not usable in a web-based forum. Stephen J. Turnbull, who is one of the developers of the Mailman mailing-list manager—used by python-ideas and others—had a lengthy reply that acknowledged the longtime tension between forums and mailing lists. Like the subject of the PEP, discussion media has been batted around in the Python community for quite some time. According to Turnbull, it boils down to this:

The main advantage to using email is that management of multiple high-traffic streams requires smart, highly configurable clients. These have been available for mail since the late 80s. They've only gotten better since. Forums, on the other hand, are based on thin clients (ie web browsers), and so you get only the configuration the forum offers, and you have to tell the forum all about it. Of course we are hackers: all the main browsers are scriptable, the language is javascript, so we could write our own forum clients. But that's exactly what forum advocates want to avoid, at least if you call it "email".

The problem for mail advocates is the flip side of that. That is, AFAIK there is no good mail software that runs in a browser (let alone a smartphone), and change of mail clients, like religions and programmer's editors, is advocated only at risk to limb and life.

Oleg Broytman also offered up his analysis of web forums versus mailing lists in the thread; it reiterates some of what Turnbull said while adding some other points. Forums may have a lower barrier to entry, but it simply isn't possible for everyone to apply their own customizations to any particular forum installation—not to mention trying to get a single, cohesive "look and feel" across the many different forum implementations available. Email may lack for some things, but it is a simple format that has a myriad of ways to access it—including from the web.

But there is a hybrid solution available: Mailman 3 (MM3). Currently python-ideas is managed by Mailman 2, but some smaller Python mailing lists have made the switch and python-ideas will likely follow soon. Switching to MM3 brings the HyperKitty archiver along with it. HyperKitty provides a web-forum-style archiver, where users can browse, post, and reply to mailing list messages. As Guido van Rossum said: "I think this is the best of both worlds."

Nick Coghlan suggested that python-ideas be used as a guinea pig for migrating some of the larger mailing lists (including, eventually, python-dev) to MM3. Few seemed opposed to the idea, though it will bifurcate the archives; after the switch, all of the newly archived messages will have a different URL. Someone could perhaps convert the old archives to the new (while preserving the existing links) at some point.

This is a discussion that goes on in various parts of our communities with some frequency. We looked at a similar discussion regarding python-ideas back in February 2016. We will certainly see it again. Email is increasingly falling out of favor as a communications mechanism, so the push for alternatives is only likely to grow stronger over time. It is not that hard to imagine that new developers in five or ten years (or ...) will not have even heard of email except as something the old-timers talk about—like gopher or rotary telephones.

Meanwhile, back at the PEP. Angelico posted a second version based on the feedback he had received. It provided more examples, a list of syntax alternatives, as well as discussion of the consequences of Python execution order. Several people in both threads thanked Angelico for creating the PEP as a place to hold the various pieces of the discussion of this feature. The clear implication is that many think PEP 572 will be rejected, but that it is valuable nevertheless. Angelico will not be surprised if that happens:

That's fine :) I'm under no illusions that everyone will adore this proposal (hey, I'm no more than +0.5 on it myself). The greatest goal of this PEP is to record the arguments for and against each of the viable alternatives, as a long-term document.

Most of those commenting on the revision are either against the idea of SLNBs entirely or would like to see a different syntax used to specify them. There is no major agreement on which of the half-dozen alternatives is best, though, so it is a little hard to see Van Rossum (who has been conspicuously silent on the feature) jumping in to resolve the syntax question in some kind of positive ruling on the PEP. A much more likely outcome is that PEP 572 gets rejected, but that python-ideas moves in a direction that makes it more friendly for those who prefer forums for discussion. The next time the SLNB feature rears it head in email or on the web, though, folks can point to PEP 572 and not have to rehash it all again.



to post comments

Discussing PEP 572

Posted Mar 14, 2018 23:00 UTC (Wed) by k3ninho (subscriber, #50375) [Link] (5 responses)

From here, away from this effort, just which part of Common Lisp are they re-implementing?

:-P
K3n.

Discussing PEP 572

Posted Mar 15, 2018 12:35 UTC (Thu) by peter-b (guest, #66996) [Link] (4 responses)

let, I think
(setq stuff
      (map (lambda (x) (let v (f x) (list v v)))
           (range 5)))

Discussing PEP 572

Posted Mar 15, 2018 17:44 UTC (Thu) by nybble41 (subscriber, #55106) [Link] (3 responses)

But Python already has something equally capable:

> stuff = [ (lambda y: [y, y])(f(x)) for x in range(5) ]

In general any non-recursive "let" can be replaced with a call to a lambda function with the variables as parameters and their values as arguments.

The introduction of "statement scope" seems a bit odd. In most languages local bindings like this are scoped over the expression, not the enclosing statement. With expression scope you don't get issues with shadowing variables used elsewhere in the statement ("b = (3 as b)"). Expression scope would also eliminate the possibility of circular references like "[(a as b), (b as a)]".

If a dedicated syntax is desired, I would suggest something like:

> stuff = [ f(x) as y in [y, y] for x in range(5) ]

Compared to the lambda form, this has the advantages of placing the variable name near its value and not requiring parentheses. Compared to the PEP, the scope of the binding seems (subjectively) more intuitive, and it becomes easier to reason about the effect: replacing "x" with "x as y in y" should never affect the overall result, even if "y" is used elsewhere in the statement (including in "x").

Discussing PEP 572

Posted Mar 16, 2018 10:59 UTC (Fri) by jag (subscriber, #3766) [Link] (2 responses)

Out of these three:

  stuff = [ (lambda y: [y, y])(f(x)) for x in range(5) ]

  stuff = [ [(f(x) as y), y] for x in range(5) ]

  stuff = [ f(x) as y in [y, y] for x in range(5) ]

I find the third line the easiest to read and understand, though the "in" bit should be allowed to be omitted:

  #while (sock.read() as data in data):
  while (sock.read() as data):
      print("Received data:", data)

(Bike-shedding is fun!)

Discussing PEP 572

Posted Mar 22, 2018 17:13 UTC (Thu) by welinder (guest, #4699) [Link] (1 responses)

Is there an official rule that things in Python have to look different than the
same thing in other languages?

It's just a let-expression, so calling it "let" would be the obvious thing.

Discussing PEP 572

Posted Mar 22, 2018 17:59 UTC (Thu) by anselm (subscriber, #2796) [Link]

Obvious perhaps, but the people in charge of Python are understandably reluctant to introduce new keywords, which is always a problem for backwards compatibility.

Discussing PEP 572

Posted Mar 14, 2018 23:54 UTC (Wed) by zblaxell (subscriber, #26385) [Link] (5 responses)

Most email clients that I don't use have no concept of threads as trees: no way to display an inbox summary as a tree, no way to select branches of the tree for future notification, no way to ignore branches of the tree, no way to navigate the tree (i.e. "read parent", "read replies", "read next sibling"). This makes them useless for technical work. Unfortunately something like 95% of email users use these email clients. After decades of Outlook and GMail, most users are unaware that better email clients even _exist_, so nobody is bothered with trying to improve the incumbents.

Disturbingly, many web forums also lack the tree concept, so even if you interact with one through an email client, you lose the tree structure when someone replies through the forum (or vice versa) because the thread tree metadata is lost every time a message goes through the forum. It turns any issue that has more than a few dozen comments into a useless mass of text with no metadata. People using that kind of forum are quickly forced to split topics up into top-level issues just to work around the forum software, but then the problem morphs into "too many top-level issues to navigate through" instead of "no thread tree metadata to organize discussion" and the root cause of the problem remains unsolved.

Smartphone email clients suck. If the phone can't selectively notify based on arbitrary header fields then it's going to be silent all the time or buzzing continuously. I do participate in mailing lists on my smartphone but I implement the notification filtering at my mail host (and wow the mangling of headers I have to do to get GMail to work with that).

Thunderbird has support for thread trees, but Thunderbird's mail filter language is not able to express rules like "show only new mail that is not ignored by thread and has none of the following three subject lines." It implements a set of non-orthogonal boolean operators that cannot be combined to form a NOR gate, an asymmetric set of message mutation operators that cannot invert the effect of a boolean OR expression, and no support for regular expressions, let alone Perl-compatible ones that could select all three subjects without using the boolean operators. Mutt's search pattern expressions have exactly none of those problems. Thunderbird maintainers did extra work to create them.

Discussing PEP 572

Posted Mar 15, 2018 0:43 UTC (Thu) by karkhaz (subscriber, #99844) [Link]

Thanks for your comment, I'm always interested to read about people's email setups. When you ignore a (sub-)thread with mutt, does that really persist between invocations of mutt? I use mutt and I can't see how this would be true.

After years of fighting clients to make them do what I want, I gave up and now do everything through mailbox manipulation. If I want to ignore a thread, I manually move the message at the root of that thread to a mailbox called "hell". Whenever I get new mail, if that email's References header contains the Message-ID of an email in hell, then a script moves that email to a mailbox called "damned", which I never read. (hell and damned are distinct so that I can keep only a single message of a thread in hell, thus keeping the list of threads to check small). (I also have mailboxes called "purgatory," "blessed," and "heaven" for various other things, and "hell" is also where I mentally consign anybody that suggests that communication should be done over anything other than email or IRC).

This has the advantage that I don't depend on clients to organise my email. I use mutt as a fairly dumb viewer of my mailboxes. If mutt ever stops being maintained, or if I stop being a Luddite and decide to install a mail client on my phone, then I still have the same experience, because my mail sorting is being done on one machine with the scripts that I wrote, and saved back to the IMAP server.

K9

Posted Mar 15, 2018 17:44 UTC (Thu) by david.a.wheeler (subscriber, #72896) [Link] (2 responses)

K9 isn't the be-all of email clients, but it understands threads and PGP. It's OSS and works on Android. Works for me.

K9

Posted Mar 20, 2018 12:18 UTC (Tue) by cortana (subscriber, #24596) [Link] (1 responses)

It's a pain that it doesn't understand IMAP subscriptions or keywords though...

K9

Posted Mar 24, 2018 12:45 UTC (Sat) by ceplm (subscriber, #41334) [Link]

Your help on https://github.com/k9mail/k-9/issues/2615 and https://github.com/k9mail/k-9/issues/769 would be always welcome, I suppose.

Discussing PEP 572

Posted Mar 17, 2018 18:29 UTC (Sat) by Creideiki (subscriber, #38747) [Link]

In the interest of staving off potential accusations of unfairness, I seem to recall that, last time I was forced to use Outlook, it was possible to beat it into submission enough that it showed messages in a tree. I doubt it had any concept of tree navigation or filtering, and it actively tried to discourage replying properly (a warning saying "It looks like you're not responding to the latest message in the conversation" or some similar nonsense).

Also, I sometimes wonder what the world would have looked like if LysKOM, the world's best messaging system that nobody has ever heard of, had spread beyond Swedish academic computer societies. E-mail-like threads? Check. Forum-like topics? Check. Rich filtering capabilities? Check. Invitation-based closed groups? Check. Clients for every environment you can think of? Check. Integration with other systems? E-mail and RSS are already available, others would be easy to write if you want them. Time-tested? The first public message is from October 1990, and the system is still in use today.

APIs, collaborative functions and social media

Posted Mar 16, 2018 9:15 UTC (Fri) by ber (subscriber, #2142) [Link] (2 responses)

Some forums offer an API via HTTPS, so building custom clients is possible which would enable customization and scripting. They may or may not be easier to adapt than doing a complex setup of an email client. And of course it stays a problem that there is no common standard.

Additional clients usually are only done for very dominant social media platforms. And those platform usually hinder the building of real client alternatives by either technical or legally restricting the use of the API. Other than this, they have the potential to also replace mailinglists or forums.

Forums do offer some more collaborative features compared to mailinglists like up- or down-voting of good responses or tagging. Then there is editing of posts. As a consequence existing "good" forums are providing a better archive of knowledge, by faster access of a summary and relevant arguments.

APIs, collaborative functions and social media

Posted Mar 16, 2018 13:34 UTC (Fri) by hkario (subscriber, #94864) [Link]

sure, everything can be done, but there's limited amount of time to do it

and reimplementing a sane interface for every forum one visits (in the dark times when every ML migrated to a forum) will quickly make one insane

APIs, collaborative functions and social media

Posted Mar 16, 2018 23:34 UTC (Fri) by lsl (subscriber, #86508) [Link]

> Forums do offer some more collaborative features compared to mailinglists like up- or down-voting of good responses or tagging. Then there is editing of posts. As a consequence existing "good" forums are providing a better archive of knowledge, by faster access of a summary and relevant arguments.

An "archive" that vanishes when the forum operator gets bored with it. Editing of posts evolves into a plague as soon as people start to use it for something other than fixing obvious typos. You get discussions that no longer make any sense to the reader because someone thought it was a good idea to delete or edit posts. Even benign amendments to a post (clearly labeling any changes) are broken in 99% of forum software as it doesn't send new mail to users subscribed to the topic.

With email, I can actually trust the archive as it's kept on my machines and not subject to the whims of other people.

Discussing PEP 572

Posted Mar 22, 2018 5:51 UTC (Thu) by ssmith32 (subscriber, #72404) [Link]

This. Is. Awesome. My product manager has been eagerly looking for examples of bikeshedding, ever since I brought up the term.

And debate about an obscure feature that allows for some optimization devolving into a debate over what tools to use to have the debate. I cannot think of a better example....


Copyright © 2018, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds