Python and Java Compared?

D-Man dsh8290 at rit.edu
Tue Apr 3 13:45:10 EDT 2001


On Sun, Apr 01, 2001 at 01:46:25AM -0800, Dry Ice wrote:
| First, I'd most like to hear from those
| who have some balanced experience at BOTH,
| as opposed to 'fans' of one or the other who
| have only dabbled in a secondary effort.

I am currently employed to do Java work.  I learned Python on my own
prior to this.

| If you had to choose...

I choose Python!


My Opinion/Viewpoint :

    Java :
        - static typing gets in the way more than it helps
        - why are Object, int, char, float, boolean, double, short,
          long, (etc) and all of the above as an array different types
          requiring the duplication of code into many functions simply
          to handle them?  (see System.out.print( * ) for an example)
        - it is not completely OO -- int, char, etc aren't objects!
          neither are classes or functions!
        - "Hello World" is harder than in C (just a case-study for the
          rest of the language)
        - reflection is hard (err, at least you have to type a lot of
          code and mention or catch lots of exceptions)

        + it does have GC (at least)
        + automatic pointer dereferencing


    Python :
        + easy
        + doesn't get in the way (_very_ flexible to suite your needs)
        + fun to use
        + uniform (ALL things are objects, even classes)
        + high level (has dictionaries and lists builtin)
        + fast enough (if not faster, using CPython)
        + since classes are objects, "reflection" is as easy as
          non-reflectively creating instances
        + has GC and auto pointer dereferencing as well

        - less marketing power and hype behind it may make it a harder
          sell to the bosses


Someone said that new stuff is usually avaible for Java before Python
(due to Sun and others' marketing power, etc).  Not quite true -- use
Jython for full access to all things Java!


I have been putting together a unit testing framework for my employer
(the Java product).  I used Jython and PyUnit to build the initial
framework.  I'll be explaining it to my coworkers/bosses (I am a co-op
right now) soon.  If they like it, it wil stay as Python code.  If
not, I'll have to convert it to Java.  It will be much more difficult
in Java due to it's static type system and reflection mechanism.

If you want access to Java stuff and Jython is too slow, you can write
parts in Java.  From the python side, integration is seamless.  Ex:


import javax

f = javax.swing.JFrame()
f.getContentPane().add( javax.swing.JLabel( "Hello World" ) )
f.setVisible( 1 )

(you could also use   from javax.swing import JFrame , JLabel  )


If you need/want to run in browsers, use jython to generate Java
bytecodes from your Python source and pack it up in a jar.

-D





More information about the Python-list mailing list