Python from Wise Guy's Viewpoint

Fergus Henderson fjh at cs.mu.oz.au
Wed Oct 29 04:58:38 EST 2003


Pascal Costanza <costanza at web.de> writes:

>Fergus Henderson wrote:
>
>> Pascal Costanza <costanza at web.de> writes:
>
>>>Well, the research that ultimately lead to the HotSpot Virtual Machine 
>>>originated in virtual machines for Smalltalk and for Self. Especially 
>>>Self is an "extremely" dynamic language, but they still managed to make 
>>>it execute reasonably fast.
>> 
>> Please correct me if I'm wrong, but as I understand it, iterating over a
>> collection of values is still going to require keeping some representation
>> of the type of each element around at runtime, and testing the type for
>> each element accessed, in case it is not the expected type.  AFAIK neither
>> HotSpot nor the Self compiler do the kind of optimizations which would
>> be needed to avoid that.
>
>You don't need to check the type on each access. If you only copy a 
>value from one place to other, and both places are untyped, you don't 
>need any check at all.

Great.  I feel so much better now.  Now my type errors are free to
propagate throughout my program's data structures, so that when they
are finally detected, it may be far from the true source of the problem.

But the example that I was thinking of did actually want to access the
value, not just copy it.

>Furthermore, if I remember correctly, dynamically compiled systems use 
>type inferencing at runtime to reduce the number of type checks.

In cases such as the one described above, they may reduce the number of
times that the type of the _collection_ is checked, but they won't be
able to avoid checking the element type at every element access.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.




More information about the Python-list mailing list