On Fri, Jun 22, 2018 at 11:28:45AM -0700, Chris Barker via Python-Dev wrote:
On Fri, Jun 22, 2018 at 10:09 AM, Michael Selik firstname.lastname@example.org wrote:
I forgot to add that I don't anticipate changing my lesson plans if this proposal is accepted. There's already not enough time to teach everything I'd like. Including a new assignment operator would distract from the learning objectives.
nor would I. For a while, anyway....
But once it becomes a more common idiom, students will see it in the wild pretty early in their path to learning python. So we'll need to start introducing it earlier than later.
Students see many features early in their path. I've had people still struggling with writing functions ask about metaclasses. People will see async code everywhere. We don't have to teach *everything* at once.
The *subtleties* of assignment expressions might have some funny corner cases, but the high-level overview is simple. It is like ordinary assignment, but it is an expression that returns the value being assigned. So if you absolutely need to teach it to a beginner, it shouldn't be difficult once they understand the difference between an expression and a statement.
I really have no idea how much harder thats going to make the langauge to teach, but it will make it a bit harder -- I see enough confusion with "is" vs == already...
I think that the biggest source of confusion with "is" is that it *sometimes* seems to do what is wanted, i.e. test equality, but other times doesn't. It is that inconsistency that bites.
Whereas with assignment expressions, there's no such inconsistency:
- regular assignment using = only works as a statement, always; - assignment expression can go anywhere an expression can go, always; - regular assignment never returns a value; - assignment expression always returns a value; - regular assignments have lots of complex forms, such as sequence unpacking, and complex targets like spam[eggs](arg).attr; - assignment expressions only takes a plain name, always.
Although there is some overlap in behaviour between the two, unlike "is", there's no inconsist behaviour to lead people astray.
A better syntax error for things like this:
py> if mo = regex.match(string): File "<stdin>", line 1 if mo = regex.match(string): ^ SyntaxError: invalid syntax
will also help, although of course some users won't read error messages for love or money.