file_ref = open(string_ref)

Greg Weeks weeks at vitus.scs.agilent.com
Tue Apr 23 12:37:25 EDT 2002


Is this code

C1:	file_ref = open(string_ref)

better than this?:

C2:	file = open(string)

C1 is more accurate, given the view that data in Python are references to
objects.  According to this view, the left-hand variable names a reference
to a file object.

I can't believe that C1 is superior to C2 or that the millions of lines of
Python, Lisp, and Java code similar to C2 are in any way wrong.  So, in my
opinion, our view of data is wrong.  To align our view of data to our code,
we need to replace the view

V1:	Objects are regions of memory.

with:

V2:	Objects are addresses (of regions of memory).

If we adopt V2, then C2 (and all the code like it) is correct.  file is an
object, string is an object, and even open is an object.  If we prefer V1,
on the other hand, then we must consider C1 more correct.

The problem with V1 is not simply a mismatch between our concepts and our
Lisp, Java, and Python code.  The sad fact is that the majority of C code
that I've seen resembles C1.  This code is just as ugly and unnecessary in
C as it would be in Python.

So, every now and then, I raise the "Objects are addresses" flag.


Greg


PS: Note that I don't proclaim "Objects are references".  The term
"reference" is ambiguous and heavy with misleading connotation.

PS: In "Objects are addresses", "Objects" does not include the numerical
values of Java or the numerical or structure values of C.  If this is a
problem, then V1 has the same problem.

PS: What about C++.  Ucch, the worst.  C++ extravagently supports V1 by
allowing "initialization by reference", whereby a variable is initialized
to the same region of memory as another variable.  The result is
considerably more complicated than Python, Lisp, and Java.  And it doesn't
quite hang together, since there is no assignment by reference.



More information about the Python-list mailing list