[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] squeezing a little fun out of java ... meh



Hello,

On 03/01/12 09:52 AM, Ian Mallett wrote:

    From my
    deeply uneducated standpoint it seems to me like this wouldn't be a
    horribly hard thing to do, to add static typing or enforced types to
    python.

From a programmer's perspective, I /don't/ see it as easy to add support for static typing to Python. It really must be all there or all /not/. And having it /not/ is one of the beauties of Python. It also made it slower. However, it's a tradeoff the language designer(s) always have to make; it can't really happen at the coders' level.

I suppose you could do things like:
def my_func(in):
    if type(in) != type(""): raise ValueError()
. . . which emulate static types, but is still not a compile-time error. In my early Python libraries, I found I was doing something of this sort because I wanted it to be robust, even at the cost of performance (this is a case where C++ wins: C++ is plenty fast, you don't have to do this particular kind of error checking, and you can put #ifdef/#endif around error-checking sections so that the code isn't even /there/ when you don't want it).


You know, there is even a Python builtin for this: isinstance

Oh, and Python 3.2 adds Abstract Base Classes, which group types by common features rather than inheritance. They serve a purpose similar to Java interfaces.

Lenard Lindstrom