The Industry choice

Donn Cave donn at drizzle.com
Sun Jan 2 01:26:39 EST 2005


Quoth Paul Rubin <http://phr.cx@NOSPAM.invalid>:
| beliavsky at aol.com writes:
|> Overall I agree with you and would like to have OPTIONAL static type
|> declarations in Python, as has often been discussed. But without
|> facilities for generic programming, such as templates in C++, static
|> type declarations can force one to duplicate a LOT of code, with one
|> sorting routine each for integer, floats, strings, etc.
|
| I don't see that big a problem.  The current Python sorting routine
| operates on instances of class "object" and calls the __cmp__ method
| to do comparisons.  Every class of sortable objects either defines a
| __cmp__ method or inherits one from some superclass, and sort calls
| those methods.  Static type declarations would not require writing any
| additional sorting routines.

Yes, it would be really weird if Python went that way, and the
sort of idle speculations we were reading recently from Guido
sure sounded like he knows better.  But it's not like there aren't
some interesting issues farther on downstream there, in the compare
function.  cmp(), and str() and so forth, play a really big role in
Python's dynamically typed polymorphism.  It seems to me they are
kind of at odds with static type analysis, especially if you want
type inference -- kind of a type laundering system, where you can't
tell what was supposed to be there by looking at the code.  Some
alternatives would be needed, I suppose.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list