anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Mon Jul 14 21:40:27 EDT 2003


On Mon, 14 Jul 2003 00:07:44 -0700, Erik Max Francis <max at alcyone.com>
wrote:

>Stephen Horne wrote:
>
>> Imagine, for instance, changing all assignments and other 'copying' to
>> use a copy-on-write system. Then add a pointer type and a 'newcopyof'
>> operator. And nick the C-style prefix '*' for dereferencing and add
>> '&' as a 'make a pointer to this object' operator (absolutely NOT a
>> physical memory address).
>
>The problem is that this misses the point that Python is not C++.  You
>shouldn't try grafting syntaxes and approaches that make Python look
>more like C++, you should be learning to use Python on its own merits.

Not true.

If you eliminate all violations of the idea of variables bound to
values (basically the whole point of my thread), then mutable
containers cannot achieve the same thing.

If a copy-on-write scheme is added to Python, you'd get the following
results from using mutable containers...

>>> a = [1, 2, 3]
>>> b = a
>>> b[2] = 4
>>> a
[1, 2, 3]
>>> b
[1, 2, 4]

That is, mutability of the list object could be used to conveniently
and efficiently rebind the variable b (in this case to the value [1,
2, 4]) but that doesn't implicitly rebind the variable a which has
nothing to do with this assignment. In the implementation, Python
would create a copy of the object bound to [1, 2, 3] just in time to
apply the change that object, without affecting the object that a is
bound to.

Efficient, and it implements the variable-bound-to-value concept.

Having done this, there would be a need for a way of indirectly
referencing objects. You wouldn't be able to abuse containers for this
goal. Pointers are the logical way to achieve the goal of indirect
referencing - they don't need to be associated with a type of
container which may have nothing to do with the problem, and they can
be used to reference *any* type of object.

>Or, to put it another way, if you want to program in C++, why not use
>C++?

I don't want to program in C++ (though sadly I have to).

The concept of a pointer as an indirect way of referencing an object,
however, is useful. It isn't just a C++ concept. It is a widely used
concept from many languages which has gone out of fashion, mainly
because of the low level detail of how pointers are implemented in
languages such as C++ (ie simple store addresses).

I don't want the C++ bug-prone implementation of pointers. I want
something which allows indirect referencing of objects in a logical
and safe, high level way - and something which doesn't require the
language to break the principle of variables bound to values.

The fact that pointers are generally useful can be seen in the regular
abuse of single item lists to fake the functionality of pointers.

If people are routinely faking the abstraction, maybe that is because
it is a useful abstraction to have. Maybe it would be better to
support it explicitly instead of forcing people to use tricks and
hacks.





More information about the Python-list mailing list