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

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



On Tue, Jan 3, 2012 at 7:19 AM, Sean Wolfe <ether.joe@xxxxxxxxx> wrote:
Well working in java continues to suck. I wish I had more experience
in C/cpp, working on it, because then I could be a little less biased
on evaluating java. I mean my frustrations with curly brace completion
and strong typing aren't a limitation of java per se.

I've been reading a lot about the relative merits of static vs duck
typing and a plus on the strongly-typed side seems to be, catching
bugs in the editor or at compile time as opposed to runtime.
Yes.  That's a primary benefit of statically typed languages--the compiler can do some of the brain work for you.  There are plenty of other examples, too (e.g., const-correctness in C/C++ and the "throws" declaration in Java).
 
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).

On the flip side, it's actually surprisingly easy to add duck typing (of a sort, through polymorphism) to compile-time languages.  In Java, simply make everything type "Object".  E.g.:
Object my_var = new String("Help!  Spiders!");
my_var = new Integer(6);

I mean we could make cholices as we code as to what to use.
When it was better to use a strongly typed methodolgy we could
refactor our code. We could use the feature as needed, and continue
with duck typing for normal python ness.

Also, although coding in Java sucks massively and gives me no joy or
happiness in life, I am finding a glimmer of hope and encouragement
using this libgdx gaming framework which at least is made by game
enthusiasts and uses cool terminology like 'Actor' and 'Stage' as
opposed to Canvas and BitmapDrawable or worse ... java.util.List .
Lord save me from java.util.List .

Just a little rant to start of 2012 in the right way.

Happy new year!! And remember. press on, it's only a flesh wound!
Ian