copy on write

Evan Driscoll edriscoll at
Fri Jan 13 17:48:29 EST 2012

On 01/13/2012 03:20 PM, Neil Cerutti wrote:
> They perform the same action, but their semantics are different.
> operator+ will always return a new object, thanks to its
> signature, and operator+= shall never do so. That's the main
> difference I was getting at.

I was talking about the combination of + and =, since the discussion is 
about 'a = a + b' vs 'a += b', not 'a + b' vs 'a += b' (where the 
differences are obvious).

And I stand by my statement. In 'a = a + b', operator+ obviously returns 
a new object, but operator= should then go and assign the result to and 
return a reference to 'a', just like how 'a += b' will return a 
reference to 'a'.

If you're working in C++ and overload your operators so that 'a += b' 
and 'a = a + b' have different observable behaviors (besides perhaps 
time), then either your implementation is buggy or your design is very 


More information about the Python-list mailing list