Wednesday, November 17, 2004

python static typing should be protocol adaptation

This post is about this link

Glad to hear that. As for me, I'd love it if function arguments, only,
could bear an 'as' clause (making 'as' a keyword is long overdue):

def x(y as foo, z as bar):
body of x

translating into:

def x(y, z):
y = adapt(y, foo)
z = adapt(z, bar):
body of x

where builtin 'adapt' does protocol adaptation. On the other hand, if
the semantics of those 'as' clauses were something like:

def x(y, z):
if type(y) is not foo: raise TypeError, 'y must be foo'
if type(z) is not bar: raise TypeError, 'z must be bar'
body of x

then that's the day I move to Ruby, or any other language that remained
halfway sensible (if any).

Of course adaptation is posible already using decorator functions, or if using PyProtocols someone can also go having all kinds of contracts, the simplest would be function dispatch conditions, like:

def foo(x):
def foo(x):

but anyways I beleave some syntax in the language for stuff like that will make people actualy use them more often.
I beleave there are lots of people in python coming from C, VB, Java like languages, who have a harder time using them, while others coming from Lisp who had them all since forever will say finaly, oh God what took you so long.
Designing with different conceps it's never going to be easy. To put this in paradoxical terms, nobody never love anything unless they already do.


Post a Comment

<< Home