Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Neil Cerutti Newsgroups: comp.lang.python Subject: Re: copy on write Date: 13 Jan 2012 16:54:35 GMT Organization: Norwich University Lines: 33 Message-ID: <9nb5ubFu17U2@mid.individual.net> References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net PniU9lgjDUnJefOaf7dCdwoWkqldNk0LQ4diA2mZH2QXh4tIG0 Cancel-Lock: sha1:DcTSDmCykxuySq6maS+Au8Hey4k= User-Agent: slrn/0.9.9p1/mm/ao (Win32) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18927 On 2012-01-13, Devin Jeanpierre wrote: > On Fri, Jan 13, 2012 at 10:13 AM, Grant Edwards wrote: >> On 2012-01-13, Devin Jeanpierre wrote: >>> On Fri, Jan 13, 2012 at 7:30 AM, Chris Angelico wrote: >>>> It seems there's a distinct difference between a+=b (in-place >>>> addition/concatenation) and a=a+b (always rebinding), which is sorely >>>> confusing to C programmers. But then, there's a lot about Python >>>> that's sorely confusing to C programmers. >>> >>> I think this is confusing to just about everyone, when they first >>> encounter it. >> >> That depends on what languages they've used in the past and whether >> they skip reading any documentation and just assume that all languages >> work the same way. >> >> I would agree that for the majority of new users, they previously used >> only languages where an assignment operator does a "copy value", and >> that 90+ percent of the time those new users they assume all languages >> work that way. > > That isn't what I was referring to. Specifically, it confuses > almost everyone the first time they encounter it that "a += b" > is not the same as "a = a + b". If you've ever implemented operator=, operator+, and operator+= in C++ you'll know how and why they are different. A C++ programmer would be wondering how either can work on immutable objects, and that's where Python's magical rebinding semantics come into play. -- Neil Cerutti