[Tutor] Slightly OT - Python/Java

Max Noel maxnoel_fr at yahoo.fr
Mon Jan 10 02:33:39 CET 2005


On Jan 10, 2005, at 00:18, Liam Clarke wrote:

> Hi all,
>
> I've been forcing myself to learn Java, and I was wondering if
> anyone's used Jython.
> To clarify - Jython generates Java bytecode?

	I've also learnt Java in roughly 1 week last autumn, because that's 
what's used at the University of Leeds. All in all, it's a language I 
quite like, much superior to C++, although it does lack the elegance of 
Python and Ruby.
	I also found that the Swing API (for building GUIs) was remarkably 
easy to use. I can't compare, though, as I've never written GUI'd 
Python or Ruby programs (and if I did, I'd probably be using PyObjC or 
RubyCocoa anyway, so that'd be equivalent to using Objective-C).

> All that stuff with typing variables - I can understand that you'd
> want to specify when the compiler needs to reserve 64 bits for a long
> integer, but beyond that is the typing really necessary for
> performance reasons? As far as I can tell it's merely so that the
> compiler can  check for errors which could lead to security problems.
> Very frustrating. As is the true/false checking...

	Well, it has ups and downs... As you said, strong typing reduces the 
chances that a security problem will occur, and is slightly faster.
	Also, Java has something which Python lacks (yet should have): 
private/protected/public class members. In Python, everything is 
public, which I consider to be a Bad Thing(TM).

> (Also very frustrating is having lists that can be comprised only of
> one variable type.)

	First things first: don't use lists/arrays. Use Collections instead 
(classes like ArrayList, HashMap, etc.). They're much more versatile, 
and akin to lists and dictionaries in Python (sometimes even better). 
Iterators over them are supported.
	And while they can indeed only be comprised of one variable type as 
well, said variable type is Object, from which all classes derive, so 
that's not a problem (you only have to remember to cast as you get() 
something from a Collection).

> (Why can't a non-static
> method comparison be called from a static reference? What does that
> mean anyway?

	Er... What was your code like? (before and after correcting the error)

> Runtime in Python 17.605 seconds (avg over 10 runs)
> Runtime in Java     12.302 seoncds (avg over 10 runs)

	Does runtime in Java include startup? Every time you start a java 
program, it has to load a BIG runtime in memory (roughly 30 megs of 
classes -- that's both Java's curse and blessing).
	Also, this test is not a very good way to measure performance of both 
languages. Java really shines when you start going haywire with classes 
and objects -- and the program goes faster as it runs (thanks to the 
Hotspot JIT compiler, that optimizes and caches stuff in ways I don't 
really understand)

> So yes - if Jython compiles to Java bytecode, and gives that 5 seconds
> faster performance, but I write it in Python, and it gives me that 27
> minutes of not messing about counting my braces, I'm in heaven. ( I
> actually wrote a Python script to count braces.)

	Oh Ghost. You didn't actually write a Java program using a regular 
text editor, did you?
	Go and download Eclipse. Now.
	It's the best IDE in the world, and probably the main reason why I 
like Java. It has features you can't live without once you've tried 
them -- spellchecking with smart correction, auto-completion, pop-up 
help dialogs... And most importantly, code auto-formatting and 
automatic brace matching.
	And of course, it's free (and written in Java). http://www.eclipse.org

	I'm also told people are currently developing a Python plugin for 
Eclipse. That'd be the Best Thing Ever(TM).

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"



More information about the Tutor mailing list