anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Thu Jul 17 14:11:13 EDT 2003


On Thu, 17 Jul 2003 00:03:38 +0000 (UTC), Adam Ruth
<owski at hotmail.com> wrote:

>Anyway, glad we cleared that up.  Sorry about misrepresenting you, I 
>really thought you were talking about Python.  In retrospect, my 
>metaphor wasn't very clear.

And in restrospect, I appologise too - of course the disguising
pointers thing was about Python and the fact that people *do* fake
pointers. But the "when you really can't avoid pointers" had no place
being carried over as in Python you can avoid pointers (including
faked pointers).

I should have though about that before replying - what I didn't state,
I certainly did imply and wrongly. Sorry again.

>I don't see it as a side effect, I see it as the core design.  
>References are a very concrete type, they happen to be implemented as 
>pointers in C.  In Java they're not implemented as pointers, I'm not 
>sure what they're implemented with, but it isn't pointers.  In that case 
>it must pass by reference (ala Java), but the semantics in Python of 
>passing references by value is maintained.

The terms 'pointer' and 'reference' are actually different names for
essentially the same thing - an indirect way of accessing something
else. The distinction between the terms is somewhat artificial, and
the meanings vary according to your background. For example, the ML
'reference' would probably be called a pointer by a C++ programmer as
it requires explicit dereferencing using a dereference operator. But
note the word 'reference' embedded within 'dereference', even when
applied to a pointer.

Different name, different syntactic quirks, but basically the same
thing. It's just that references (as in things that don't need
explicit dereferencing) tend to limit errors simply by limiting the
ways you can use them.

I just got tired of typing 'pointer/reference'.

At some point, however, there must be some kind of manipulation of
hardware addresses - maybe in the implementation of the language,
maybe in the next layer down, or whatever. Even if you use a C
fixed-size array, the implementation in assembler is using essentially
pointer math to implement it. That pointer math is so exposed in C,
actually, that in most cases you can treat a pointer as an array and
visa versa (sizeof being the only exception I can think of off the top
of my head).

Anyway, this kind of thing is not what I want from a high level
language. What I would want (in the alternate universe I mentioned
elsewhere) is actually a simpler version of what we already have - a
mutable container that always holds exactly one item. That would do
the important jobs of a pointer, but being explicitly meant the job it
would cause less confusion and would have less potential for errors.

Even if it were dereferenced using '[0]' that is still doing the job
of a pointer. I'd simply like to see it dereferenced in a way that
doesn't suggest a '[1]' or '[2]' might be used. And in some contexts,
implicit dereferencing might well be the way to go. Variable
parameters being an important example.

>> No, my background isn't just in C - that is a long way from being the
>> first language I used, and I've used Python regularly longer than C++.
>
>I wasn't referring to you, but to the people that come to the newsgroup 
>and ask questions about it.

OK - sorry for taking that personally, then.





More information about the Python-list mailing list