Issue7867
Created on 2010-02-06 21:04 by r.david.murray, last changed 2010-02-06 22:15 by brian.curtin.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
pass_by_x.faq
|
r.david.murray,
2010-02-06 21:04
|
|
|
|
|
passbyx.txt
|
r.david.murray,
2010-02-06 22:03
|
|
|
|
|
msg98956 - (view) |
Author: R. David Murray (r.david.murray) * |
Date: 2010-02-06 21:04 |
|
A while back, after along discussion about variables and their meaning in Python on the python-list, I wrote up the attached FAQ entry to summarize what I got out of that enlightening discussion. I'm proposing that this be added to the FAQs. If this doesn't itself cause too much controversy I'll prepare a doc patch.
|
|
msg98957 - (view) |
Author: Michael Foord (michael.foord) |
Date: 2010-02-06 21:16 |
|
Wasn't the description of Python's semantics being 'pass by value where the value is a reference' actually very controversial indeed? Do you have a link to the discussion on c.l.p?
|
|
msg98958 - (view) |
Author: R. David Murray (r.david.murray) * |
Date: 2010-02-06 21:26 |
|
Well, the discussion was *long* and more than a bit contentious. This is my own personal summary. Here is a message I found somewhere in the middle of the thread:
http://mail.python.org/pipermail/python-list/2009-January/1187126.html
Do you have a pointer to where "pass by value where the value is a reference" was controversial? (Other than that thread :)
|
|
msg98959 - (view) |
Author: Ezio Melotti (ezio.melotti) |
Date: 2010-02-06 21:34 |
|
The 4-point list at the beginning is in my opinion very clear (for people with some background in C or similar languages). I think that the following part is not really clear, and the example should focus better on the difference about mutable and immutable objects.
|
|
msg98960 - (view) |
Author: R. David Murray (r.david.murray) * |
Date: 2010-02-06 21:37 |
|
Well, the thrust of the second part is to make it clear that there *are* no differences between mutable and immutable objects as far as the assignment semantics are concerned. All objects in Python are treated the same. What is different is what is on the left hand side of the assignment, and yes, it would probably be helpful to point that out explicitly.
|
|
msg98961 - (view) |
Author: Michael Foord (michael.foord) |
Date: 2010-02-06 21:45 |
|
Over 122 messages so I'm not going to search exhaustively. In this part of the thread you can see Fredrik Lundh and Aahz disputing "call-by-value-where-the-value-is-a-reference" as a useful way of describing Python calling semantices:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/37e00ba1a5200b9b/1d68c7686a9d5417
|
|
msg98962 - (view) |
Author: Ezio Melotti (ezio.melotti) |
Date: 2010-02-06 21:47 |
|
The difference is that mutable objects may give the illusion of a pass-by-reference (because changes made inside the function are visible outside) whereas immutable objects give the illusion of pass-by-value (because you can't affect the original object in any way). This is also related to the confusion about assignment and what it really does.
|
|
msg98963 - (view) |
Author: R. David Murray (r.david.murray) * |
Date: 2010-02-06 22:03 |
|
Michael: I didn't read the whole thread, but it has definite echos of the thread in which I was involved. While I agree that in pure computer-science terms it may be imprecise to say that python is 'call by value where values are pointers to objects", my goal in the FAQ entry is to give people coming from C a mental model that *works* in practical terms to help them understand what Python does.
The second half is then an attempt to provide a new mental model, one independent of any implementation details, that *better* explains what Python does.
But apparently, given Ezio's responses, I didn't succeed in the second part :(
Ezio: I've added another paragraph to the end to try to make the point I'm trying to get across clearer, but I'm not sure the additional words really do that.
|
|
| Date |
User |
Action |
Args |
| 2010-02-06 22:15:55 | brian.curtin | set | nosy:
+ brian.curtin
|
| 2010-02-06 22:03:02 | r.david.murray | set | files:
+ passbyx.txt
messages:
+ msg98963 |
| 2010-02-06 21:47:10 | ezio.melotti | set | messages:
+ msg98962 |
| 2010-02-06 21:45:06 | michael.foord | set | messages:
+ msg98961 |
| 2010-02-06 21:37:39 | r.david.murray | set | messages:
+ msg98960 |
| 2010-02-06 21:34:03 | ezio.melotti | set | nosy:
+ ezio.melotti messages:
+ msg98959
|
| 2010-02-06 21:26:15 | r.david.murray | set | messages:
+ msg98958 |
| 2010-02-06 21:16:39 | michael.foord | set | nosy:
+ michael.foord messages:
+ msg98957
|
| 2010-02-06 21:04:13 | r.david.murray | create | |
|