Decorators and static typing.

whisper at oz.net whisper at oz.net
Thu Jan 6 00:30:27 CET 2005


Well, the decorator war is over (Python lost IMO!) and now we've got the 
static typing war to fight!

Both of these seem like syntax sugar to avoid writing good code! One has 
already introduced ugly coding and the 2nd is likely to do the same!

Ok, so how do you do keywords and default values?
def myFunc(a=1: int, b="hi": string, people=[]: array[person]): int:
    yadda
    yadda
    yadda
So, what is the int or string? the default value or the label? (Of 
course it's obvious to an experienced programmer - is that the intened 
audience for Python now and the python in education initiative dead?). 
The last parameter is particularly arcane (and ugly!).

If this mistake looking for a place to happen has to happen, at least 
put the type before the horse!:
def myFunc(int a=1, string b="hi" array[person] people) int: #note lack 
of first : after "("
    yadda
    yadda
    yadda

Of course, one could not change the language at all!:
def myFunc(a, b):
    assert(type(a) == "int")
    assert(type(b) == "string")
    #aggrigates lose here - how do you check the type of every element? 
(ensure that array[person].__add__ makes sure the rhs is of type person 
so the problem never comes up in the first place!)
    yadda
    yadda
    yadda
I know: this doesn't save you from yourself when calling myFunc from 
somewhere else, but it does ensure that parameters are of the expected 
type where it really counts! (People who need saiving from themselves 
ought not to be programmers in the first place!)

Of course, decorators might have been done this last way too - with 
predefined functions and no needed changes to the language, but maybe 
that's not as cool for the dev guys. That brings up the larger problem, 
as alluded to by the "python evolution: unease" thread: the dev guys 
seem intent on more breadth without focusing on the depth of the language!

At some point, someone has to decide that python is feature complete!

Lua is looking better and better! ;=)



More information about the Python-list mailing list