Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19831
| Date | 2012-02-03 21:47 +1100 |
|---|---|
| From | John O'Hagan <research@johnohagan.com> |
| Subject | Re: copy on write |
| References | (8 earlier) <4f2a5478$0$29895$c3e8da3$5496439d@news.astraweb.com> <20120203011748.592f060f32ac79d450a2ca8d@johnohagan.com> <jgegti$c9f$1@dough.gmane.org> <mailman.5388.1328238503.27778.python-list@python.org> <4f2b6ae6$0$29989$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5396.1328266081.27778.python-list@python.org> (permalink) |
On 03 Feb 2012 05:04:39 GMT Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > On Fri, 03 Feb 2012 14:08:06 +1100, John O'Hagan wrote: > > > I think we're 12 years late on this one. It's PEP 203 from 2000 and > > the key phrase was: > > > > "The in-place function should always return a new reference, either > > to the old `x' object if the operation was indeed performed > > in-place, or to a new object." > > > > If this had read: > > > > "The in-place function should return a reference to a new object if > > the operation was not performed in-place." > > > > or something like that, we wouldn't be discussing this. > > And what should it return if the operation *is* performed in-place? Not knowing anything about the inner workings of the interpreter, I'm agnostic on that as long as it's not "a new reference". Perhaps the old reference? [...snip undoubted reasons why returning None wouldn't work...] I don't know what would work. Maybe it is insoluble. But didn't Hrvoje Niksic's post in this thread suggest it could have been implemented to work the way I'm saying, even supplying code to demonstrate it? All I'm saying is that however it's implemented, x[i] += y should simply mutate x[i] in-place if x[i] implements that, otherwise it should do x[i] = x[i] + y. If I can say it under 25 words, surely it's implementable? (Whether it's practical to do so is another question.) The x[i] in x[i] += y can be seen as a reference to an object to be incremented rather than an assignment (despite the name). In that view, whether the name x[i] needs to be rebound to a new object, resulting in an assignment, depends on the capabilities of x[i], not x. > > Yes, the current behaviour is a Gotcha, but it's a Gotcha that makes > good sense compared to the alternatives. I think it's worse than a Gotcha. IMHO a Gothcha is, for example, the mutable default arguments thing, which makes sense once you get it. This one has the bizarre consequence that what happens when you operate on an object depends on which name you use for the object. Not to mention that it succeeds after raising an exception. > Ultimately, augmented assignment is *assignment*, just like it says > on the tin. t[1] += x is syntactic sugar for t[1] = t[1].__iadd__(x). > It can't and shouldn't fail to raise an exception if t is a tuple, > because tuple item assignment *must* fail. That makes sense if we view it strictly as assignment (but in that case the mutation of t[1] should not occur either). But isn't it equally true if we say that z = t[1], then t[1] += x is syntactic sugar for z = z.__iadd__(x)? Why should that fail, if z can handle it? [...] > > Ultimately, there is no right answer, because the multitude of > requirements are contradictory. No matter what Python did, somebody > would complain. > Not complaining, just trying to contribute to the best of my ability. :) John
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
copy on write Eduardo Suarez-Santana <esuarez@itccanarias.org> - 2012-01-13 11:33 +0000
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-13 12:10 +0000
Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-01-13 23:30 +1100
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-13 13:04 +0000
Re: copy on write Ethan Furman <ethan@stoneleaf.us> - 2012-01-13 10:40 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-13 14:26 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-13 14:26 -0800
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-02 14:18 +1100
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-02 01:34 -0500
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-02 19:11 +1100
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 09:16 +0000
Re: copy on write Hrvoje Niksic <hniksic@xemacs.org> - 2012-02-02 11:53 +0100
Re: copy on write MRAB <python@mrabarnett.plus.com> - 2012-02-02 16:28 +0000
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-02 12:21 -0500
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 01:17 +1100
Re: copy on write Terry Reedy <tjreedy@udel.edu> - 2012-02-02 12:25 -0500
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 14:08 +1100
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-03 05:04 +0000
Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-02-03 16:28 +1100
Re: copy on write Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-03 07:35 -0800
Re: copy on write Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2012-02-03 10:08 +0100
Re: copy on write John O'Hagan <research@johnohagan.com> - 2012-02-03 21:47 +1100
Re: copy on write Wolfram Hinderer <wolfram.hinderer@googlemail.com> - 2012-02-05 06:09 -0800
Re: copy on write "OKB (not okblacke)" <brenNOSPAMbarn@NObrenSPAMbarn.net> - 2012-02-03 16:15 +0000
Re: copy on write Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-02-02 11:42 +0100
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-13 08:50 -0500
Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 15:13 +0000
Re: copy on write Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-13 11:48 -0500
Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 16:54 +0000
Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 18:15 +0000
Re: copy on write Chris Angelico <rosuav@gmail.com> - 2012-01-14 05:26 +1100
Re: copy on write Grant Edwards <invalid@invalid.invalid> - 2012-01-13 19:30 +0000
Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 20:11 +0000
Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-01-13 13:24 -0600
Re: copy on write Neil Cerutti <neilc@norwich.edu> - 2012-01-13 21:20 +0000
Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-01-13 16:48 -0600
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-02 05:33 -0800
Re: copy on write Evan Driscoll <edriscoll@wisc.edu> - 2012-02-02 15:20 -0600
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-02 05:33 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-03 14:16 -0800
Re: copy on write 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-03 14:16 -0800
Re: copy on write Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-01 19:51 -0800
Re: copy on write Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 05:31 +0000
csiph-web