[Tutor] Sun says: Don't use Java, use Python!

Paul Tremblay phthenry@earthlink.net
Tue Feb 11 01:23:03 2003


On Mon, Feb 10, 2003 at 11:38:58PM -0500, Erik Price wrote:
> 
> On Monday, February 10, 2003, at 08:09  PM, Paul Tremblay wrote:
> 
> >The script will be over 3,000 lines long. In order to parse the RTF, it
> >has to make a dozen or so passes through the file. The reason for so
> >many passes is that RTF is very dense. I had written a successful perl
> >script that parsed RTF in one pass, but the script is almost 
> >unreadable.
> >
> >The newer perl script (not the one above) makes a module for each pass
> >through the file. I thought this was bad design, because I had a dozen
> >or so modules.
> >
> >But you are telling me that it is perhaps best to keep the script
> >modular?
> 
> [If I ever had to read your script's source code,] I would say so.  One 
> of the things that I do like about Java is that it forces the 
> programmer to split their code up into separate files (similar to what 
> Python does with whitespace and indentation).  Each file contains its 
> own public class.  It's not exactly convenient for quick work, but 
> that's people generally wouldn't use Java for scripting (after all 
> there's Python!).
> 

Yes, if you had to read my source code of the original script you would
probably send me a nasty email. I knew that I would have to maintain the
code; hence, the change to a modular design.

However, the new modular design is 3 times as slow! It took 50 seconds
to parse a dense file on a slow, 100 MHZ computer. The new modular
design took 2 minutes and 20 seconds. 

Some of the speed factors could definitely be due to my inexperience.
Keep in mind that these two comparisons are both with perl scripts. I
don't know how Python will fare as far as speed is concerned. 

My reason for converting the script to Python is:

--Python is so darn elegant and easy to read

--Since it is so easy to read, others are more likely to take an
interest in the project and help out, or simply use it.

--I am thinking of converting the code to java after I convert it
to Python. I know there is a thing called Jython, but I have no idea if
I can readily conert my script to Jython.

--My reasoning for java is that Java is much faster than perl or python.
Of course, speed can be very tricky. Perl is faster at regexp than any
language. However, most of the script reads in one line at a time and
uses the substr function in perl, which is the same as slicing in
Python. I believe that Java would give the user a huge speed increase. 
However, this thread originally asserted that java was *not* that much
faster. In which case, no need to learn and struggle with java!


I agree with your statements about java forcing a programmer to uses
classes. I noticed this too, even though I know hardly any java. I guess
that accounts for my attraction to Python--it allows you to break code
into simple re-usable chunks.

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************