anything like C++ references?

Adam Ruth owski at hotmail.com
Tue Jul 15 13:45:10 EDT 2003


Stephen Horne <intentionally at blank.co.uk> wrote in message news:<rp94hvc8fg6h91oe7ctqq9jn9ku3nlud1k at 4ax.com>...
> On Sun, 13 Jul 2003 22:42:21 GMT, "Bryan" <belred1 at yahoo.com> wrote:
> 
> >
> >> 3.  Why is there no way to reference an immutable object via a
> >> pointer, other than stuffing it into a mutable object designed for
> >> some purpose other than simple pointer behaviour?
> >>
>  
> >>>> a = (1, 2, 3)
> >>>> b = a
> >>>> id(a)
>  15471760
> >>>> id(b)
>  15471760
> >>>> print b[1]
>  2
> >>>>
> >
> >
> >i just referenced an immutable object via a "pointer" and i __did_not__
> >stuff it into a mutable object as you say.
> >a and b "point" to the same object.
> 
> Technically, but what is the point? You can't do pointer-style things
> with it. You can't change the object in any way without changing the
> id, and you can't use the mechanism to, for instance, allow 'var'
> parameters.
> 
> In short, you are showing evidence of the use of pointers internally
> within Python, but that is not the same as providing pointer-like
> semantics.

I came to Python from Ada, and all I have to say is:  Pointer-like
semantics are evil.  They're worse than goto's, they're deadly,
damaging, and should be avoided at all costs.

They're an unhappy necessity, akin to stop-lights.  You need them
because roads intersect, but if roads don't intersect, don't use them!




More information about the Python-list mailing list