Favorite non-python language trick?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Jul 1 18:13:31 EDT 2005


Rocco Moretti wrote:
> Joseph Garvin wrote:
>
> I'm not aware of a language that allows it, but recently I've found 
> myself wanting the ability to transparently replace objects....
> I mainly look for it in the "object replaces self" form, but I guess you 
> could also have it for arbitrary objects, e.g. to wrap a logging object 
> around a function, even if you don't have access to all references of 
> that function.
> 
> Why isn't it in Python? It's completely counter to the conventional 
> object semantics.

Actually this is the old (and terrifying) Smalltalk message 'becomes:'.
There is a concrete reason it is not in python: objects are represented
as pointers to their data structures, do not have identical sizes, and
therefore cannot be copied into each others data space.  Smalltalk
implementations often have a level of indirection that allows it to
simply tweak an indirection table to implement this method.

The reason I find it terrifying is that I can be passed an object,
place it in a dictionary (for example) based on its value, and then
it can magically be changed into something else which does not fit
in that spot in the dictionary.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list