I don’t know what has happened to Guido - first decorators, now Static Types!
He’s come up with a scheme for optional static typing of methods. I can’t think of one case in which I’d use it. He gives an example:
def gcd(a, b):
while a:
a, b = b%a, a
return b
Which “pretty much only makes sense with ints”. Well, I can imagine that would make sense with a whole load of complex types, potentially, with overloaded % operators. One critical pattern in python, and one that I think makes it so powerful, is that you don’t test for types, you test for behaviour.
After all, it doesn’t matter if you are adding two things together what they are, only that they support the add method. It’s up to the caller to ensure that calling your function makes sense. You can determine that as the function author.
Part of the reason this works so well is because python code is available - no obfuscated bytecode distribution or .o files. You can read the source of the function you are calling.
So, no need for static typing. ewwww.
0 Responses to “Eeeep! Static Types!”