benrg added the comment:

> As far as I know Ezio is correct, "when possible" means "when the target is 
> mutable".  The documentation should probably be clarified on that point.

Yes, it needs to be made very, very clear in the documentation. As I said, I'm 
not aware of any other language in which var op= expr does not mean the same 
thing as var = var op expr. I'm actually amazed that neither of you recognize 
the weirdness of this behavior (and even more amazed that GvR apparently 
didn't). I'm an experienced professional programmer, and I dutifully read the 
official documentation cover to cover when I started programming in Python, and 
I interpreted this paragraph wrongly, because I interpreted it in the only way 
that made sense given the meaning of these operators in every other language 
that has them. Python is designed to be unsurprising; constructs generally mean 
what it looks like they mean. You need to explain this unique feature of Python 
in terms so clear that it can't possibly be mistaken for the behavior of all of 
the other languages.

> Remember, Python names refer to pointers to objects, they are not variables 
> in the sense that other languages have variables.

That has nothing to do with this. Yes, in Python (and Java and Javascript and 
many other languages) all objects live on the heap, local variables are not 
first-class objects, and var = expr is a special form. That doesn't change the 
fact that in all of those other languages, var += expr means var = var + expr. 
In C++ local variables are first-class objects and var += expr means 
var.operator+=(expr) or operator+=(var, expr), and this normally modifies the 
thing on the left in a way that's visible through references. But in C++, var = 
var + expr also modifies the thing on the left, in the same way.

In Python and Java and Javascript and ..., var = value never visibly mutates 
any heap object, and neither does var = var + value (in any library that 
defines a sane + operator), and therefore neither should var += value (again, 
in any sanely designed library). And it doesn't. Except in Python.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16701>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to