[Tutor] Sun says: Don't use Java, use Python!
Erik Price
erikprice@mac.com
Mon Feb 10 23:25:04 2003
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!).
Every [public] class gets its own file. If I'm reading through your
main script and see that you use a class called RtfReader to read and
parse RTF code, I might want to read the details of how the RtfReader
works -- or I might not. Maybe I just want to see what your main
script does for now and go into the details later. This is one of the
nice things about modules and splitting up a 3000-line program into
modular chunks.
Plus, it's a LOT easier to use your RtfReader in another script than it
is to search through the source, copy and paste the relevant code, then
modify it to work in the new script. A lesson I learned on this very
list a long time ago (I think it was Danny Yoo) was to use the "if
__name__ == '__main__'" trick. Even for the most simple of things,
like the accessor/mutator script I made for generating JavaBeans and
posted on this list last week -- I'll probably never use that module
for anything else, but in case I do, I can just import the module and
refer to the functions.
Erik
--
Erik Price
email: erikprice@mac.com
jabber: erikprice@jabber.org