Why should i use python if i can use java

Geoffrey Gerrietts geoff at homegain.com
Wed Jun 6 18:31:59 EDT 2001


mik <karmen2001 at HOTMAIL.COM> asks:
> i' m a python newbie but I've this prob. i have seen Jython ..
> 
> what has python dat java does not?????????

As someone who just recently spent a lot of time on this group explaining
Java's benefits, I think my karma may demand something of an about face. I
can't tell you what you'll like best about Python, or what you'll use most,
but I can tell you how things have worked for me.

I think it can be summed up in a sentence: Python is a lot more flexible
than Java. That doesn't mean that you can do some things in Python that you
can't in Java; it just means that some things are much easier to do in
Python than in Java. I might go so far as to say most things.

Reflection in Java is a pain in my ass. It's inconvenient and it's pretty
difficult to get at the actual methods or properties to call them. Python
makes that very simple, to the point of trivial. Python makes it very easy
to grab hold of what you want when you want it. It's a lot easier for me to
write components that can accomodate any object at all without relying on
whether standard interfaces have been implemented. It's also very easy to
manipulate functions or methods, copy them between objects, or otherwise
manipulate the results of my introspection.

Unit-testing under Python is a lot easier, or has proven so for me. Because
you have almost total control over the objects you import and use, you can
stick in "stubs" for standard library components, so that your "stub"
returns standardized values. You can also do it for user-contributed
components.

Prototyping and experimenting is easier under Python, too. I slap together a
few lines of code into a file, then python -i <filename> -- the Python
interpreter runs my lines, then gives me a command prompt, so I can
experiment with the data, try various combinations of function calls, or
otherwise validate my work.

In Python, I know how to write classes whose instances are other classes. In
Python, I know how to write a routine that generates a string of python
code, then executes the contents of the string. These are highly dynamic
features that I don't know how to exploit in Java, if it's even practical to
do so. Note that you /can/ do it in Java, but it may take you ten or twenty
or a thousand lines of Java to do what one or two or five lines of Python do
quite easily.

These are all features I can say that I've used in Python -- used the hell
out of some of them. They lack in Java, or are more difficult to access.

---
Geoff Gerrietts <geoff at homegain.com>
Software Engineer, HomeGain.com
510-655-0800 x4320




More information about the Python-list mailing list