anything like C++ references?

Aahz aahz at pythoncraft.com
Sun Jul 13 12:19:08 EDT 2003


In article <brs2hv8edfv0d1fch9mha8otuulajnkh0g at 4ax.com>,
Stephen Horne  <intentionally at blank.co.uk> wrote:
>On 13 Jul 2003 10:37:01 -0400, aahz at pythoncraft.com (Aahz) wrote:
>>In article <iqm2hvs77lhe1m71v9b579070khbf0uv0a at 4ax.com>,
>>Stephen Horne  <intentionally at blank.co.uk> wrote:
>>>
>>>One of the few things I hate about Python is that mutable objects are
>>>implicitly shared using a reference system whereas immutable objects
>>>are not. 
>>
>>Well, that's incorrect.  *ALL* Python objects are implicitly shared with
>>bindings.  The difference is whether updating the value referenced by a
>>target requires *re*binding the target or simply updating an object.
>
>Fine - nit-pick.

Believe it or not, it is *not* a nit-pick, it goes right to the core of
Python's design and philosophy.

>All you have proven is that it is the distinction between types that
>get re-bound and those that don't (rather than the use of references)
>that is unnecessarily confusing and error prone.

Only for people who insist on thinking about it through the lens of some
other way to do it.

>A Python user is interested in how an object behaves - not how it is
>internally implemented in the interpreter. Immutable objects don't
>behave as references - the internal use of references for immutable
>objects is basically a lazy copying optimisation and, apart from
>performace and a couple of other technicalities (e.g. the 'is'
>operator), has no relevance. Certainly it has no relevance to the
>point I was making.

That's precisely where you are wrong.  Python's object model is
extremely strict and simple and orthogonal.  Everything works exactly
the same way.  Whether one can mutate a specific object is simply an
attribute of that object, rather than requiring a different syntax.
Trying to focus on the mutable/immutable distinction is what causes the
mental blowup -- keep your eye on the objects and bindings and you're
fine.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Not everything in life has a clue in front of it...."  --JMS




More information about the Python-list mailing list