On 5/7/14 8:08 PM, Steven D'Aprano wrote:
In Python, all values *are* objects. It isn't a matter of choosing one or
the other. The value 1 is an object, not a native (low-level, unboxed) 32
or 64 bit int.
Unlike C# or Java, there is no direct language facility to box native
values into objects or unbox objects to native values.
Yes. In the context of the rest of this discussion, this one point
is just one of the many reasons why it is not helpful to think of
Python's {name: object} relationship as 'variable -- value'.
Typically when I think about variables (particularly from the past,
say Pascal, Basic, C, Fortran, Cobol &c) I am thinking about modeling
memory is some way where the variable (some naming convention) is a
value handle or value pointer of some chunk of memory (by type | length)
--- where I am creating a 'box' into which I may place something
(usually some native type).
When I think of Python's 'variables' (and I don't believe Python
has variables) I am now thinking of a naming convention (for handling
objects) where I am not the least interested in modeling memory for
native types. I am instead interested in modeling the real world (or
subset) with object abstractions. I am no longer interested in creating
a 'box' into which I may place some type. I don't need variables any
longer for that purpose. What I want is some very efficient naming
convention whereby I can handle the objects I am constructing (for
whatever abstract purpose).
If a programmer new to Python thinks in terms of 'variables' from C
or Pascal, or Fortran or Basic, they will run into surprises when it
comes to handling the {name: object} idea in Python. In fact, most of
the time this debate comes up it is precisely that the new user is
finding Python's 'variables' aren't behaving correctly or finding that
they are not able to 'do' what they used to do (say) with C's variables.
It really comes down to the definition of 'variable' and whether
the language in question is modeling memory, or modeling object
abstractions.
marcus
--
https://mail.python.org/mailman/listinfo/python-list