strong/weak typing and pointers

Steven Bethard steven.bethard at gmail.com
Tue Nov 2 12:35:28 EST 2004


Michael Pyle <pyle_michael <at> emc.com> writes:

> Perhaps he is refering to the ability to change the class of an instance at 
> runtime. If you can't do that in Smalltalk (all other things being equal), I'd 
> say that would indicate weaker typing.

This seems to confuse strong/weak typing with static/dynamic typing.  If we
think about an object as an allocated block of memory, changing the class of an
Python object does not change how that block of memory is interpreted[1].  It
changes the value of one field of that object, namely the field that determines
where to look for the class object[2].  The memory block is still interpreted in
the same way, it just happens that some of the fields in that block may have
changed.

The point here is that changing the class of an object does not change how the
block of memory representing that object is interpreted; it only changes how the
class (and class methods) are looked up for that object.

Steve

[1] To be clear on what I mean by "how that block of memory is interpreted", you
may want to refer to my example of weak-typing in C:
http://mail.python.org/pipermail/python-list/2004-November/248983.html
[2] This may actually be changing several fields in the object's memory block (I
don't know Python's implementation well enough) but the idea is still the same.




More information about the Python-list mailing list