Finding the instance reference of an object
callen314 at gmail.com
Tue Nov 4 18:16:05 CET 2008
On Nov 4, 11:06 am, Joe Strout <j... at strout.net> wrote:
> On Nov 4, 2008, at 7:42 AM, Craig Allen wrote:
> > coming from C/C++ Python seemed to me call by reference, for the
> > pragmatic reason you said, modificaitons to function arguments do
> > affect the variable in the caller. The confusing part of this then
> > comes when immutable objects are passed in.
> Yes, you stepped in the wrong direction right away and led yourself
> into a morass of contradictions.
> The correct way to look at it is that a Python reference is like a C++
> pointer. C++ pointers are passed by value (unless you add & to
> I'd be very interested in hearing whether, as a C/C++ user, the above
> explanation is clear and makes sense to you.
joe, yes, it makes perfect sense. In my defense my priority was
figuring out what was going on in terms of what happens passing in
various types of arguments, rather than what things are called. Also,
as a C/C++ programmer my perspective is that the program is the
interpreter, and so I try to think what the interpreter is doing.
This is ke because after 15 years of statically linked languages (no
one calls them this any more due to dynamically linked libraries) you
get used to things evaporating at compile time, the name "x" for a
variable has no status as a real entity at run time. It is a name
through which you communicate with the compiler only, the compiler has
no need to represent it in the runtime program. I think a lot of this
language history is based on terminology that does not have to
consider this name as a real entity at runtime.
When you consider the status of the entity "x" in "x=1" in python, it
is a pointer, and python looks like pass by value.
The need for a different name comes from the fact that using pointers
ubiquitously like this leads to behavior much more like pass by
I'm open to pass-by-sharing, or pass-by-object, but neither is
perticularly intuitive, not as obvious in meaning as pass-by-val or
pass-by-reference (or call-by-xxx). I suppose I'd like pass-by-name as
more a description, as "name" to me has a similar sense to pointer, at
least in a language that preserves the name as a runtime entitity
(making C/C++ languages which compile away names).
What happens in python is clear to me, I think I understand what the
program, CPython is doing... the language still needs to settle.
Thanks for the reply, it does help me find a better way to discuss
what I understand about python and calling mechanics in general.
More information about the Python-list