Terminology: "reference" versus "pointer"

Steven D'Aprano steve at pearwood.info
Sat Sep 12 20:14:30 CEST 2015

On Sun, 13 Sep 2015 03:12 am, Rustom Mody wrote:

> Best I can see, the people frothing at the mouth that python has no
> pointers are basically saying that "non-first-class" == "non-existent"

Not at all. In Python, at least, all values are first-class, but that's not
the case with all languages which lack pointers. Java has classes but they
aren't first-class values. They aren't values at all, but they do exist as
entities in Java code. You don't have to drop out of Java into some
underlying implementation language in order to write Java classes.

I trust that you agree that Fortran lacks pointers -- or at least, old
versions of Fortran, like FORTRAN 5 and (by memory) Fortran 77 lack them.
(Modern Fortran almost certain has pointers.) Old versions of Fortran lacks
dynamic memory management, it has no pointers, no equivalent of
Pascal's "new" and "dispose". It also has a variable model like C's (named
variables with fixed memory locations).

Suppose I write a Fortran 77 compiler in C. I daresay I would use C's
ability to dynamically allocate and free memory (i.e. pointers) in my
implementation of Fortran 77. But because this is a faithful implementation
of the Fortran 77 standard, warts and all, the Fortran compiler itself
won't have the ability to create, dereference or free pointers.

Would you insist that Fortran 77 has pointers just because my implementation
uses pointers under the hood?

> By that same logic C has neither types nor functions

No. C has both types and functions. You can define your own types, and you
can define your own functions.

They might not be first-class values, but they are entities you manipulate
in your C code. You don't have to drop out of the C language into (say)
machine code to write a function.

In Python, the language *lacks pointers altogether*. It's not just that you
can't treat them as first-class values, or that they aren't values, but
that they aren't even entities in the Python programming model. In order to
interact with pointers, you have to drop out of Python altogether, and
start programming in the implementation language C, or use an interface to
C such as ctypes.


More information about the Python-list mailing list