[1425] in java-interest
Java for CGI
daemon@ATHENA.MIT.EDU (Glen C. Perkins)
Fri Sep 1 18:16:26 1995
Date: Fri, 1 Sep 95 12:30 WET DST
To: java-interest@java.sun.com
From: Glen.Perkins@NativeGuide.com (Glen C. Perkins)
It seems to me that the domination of web programming should be the first
priority for Java. If it can take over the web and hold onto it, it stands
a good chance of becoming a widespread standard in the future in lots of
other programming niches. If it can't dominate the web, even with the
headstart Netscape will be giving it, it might not survive long enough for
us to ever have the tools we need to use it for standalone programming.
Since the webmasters who will be writing the web applets for a site will
also be the ones who write all the CGI scripts, too (in general), I would
like to see Java make a strong attempt (with its standard libraries) to
replace Perl as the standard CGI scripting language. If you force web
developers to use two different programming languages, Java for applets and
Perl for CGI, you're missing a great opportunity--an opportunity that
shouldn't be missed if dominating the web niche is critical to your
long-term survival.
What would it take for Java to replace Perl as the CGI scripting language
of choice? This isn't a rhetorical question. I'm actually asking.
I have a couple of ideas, though, since I'm responsible for our web
programming and have found Perl to be a WONDERFUL language for CGI
scripting. The number one reason I love using Perl for CGI scripting is
Perl's powerful regular expression parsing abilities. CGI scripts are
designed to manage incoming information which means EVERY script I write is
a parser (among other things.) I absolutely LOVE the fact that if someone
can describe the format of a data stream, even a VERY loose format, I can
create a Perl parser for it in a flash.
I've had a LOT more experience with C than with Perl, but after learning
Perl, I would never consider writing a parser with C again, unless it were
something like a device driver where speed was a major issue. If I'm going
to switch to using Java for CGI, Java is going to have to make parsing as
easy as Perl does, or almost as easy. (An object-oriented language like
Java will always require a few extra lines of "overhead" code, but that's
not a problem. I can always start with a little template.) Java can even
make it easier by enabling me to write an HTMLFormProcessor class, for
example, which I could reuse. Also, since Java is Unicode-based, it could
allow me to parse regular expressions in any language. Japanese customers
who fill out their forms in kanji wouldn't blow up my parser. Perl can't
touch this. This is the sort of thing I would be hoping to get by doing CGI
in Java instead of Perl. Don't make me have to write my parsers without
some built-in support for regular expressions, though, or I'll just use
Perl most of the time. Perl 5 has support for objects, and it would be
easier to learn how to do objects in Perl than it would be to write my own
regular expression class from scratch or to write my parsers in Java one at
a time without the benefit of a standard regular expression class.
REQUEST: let's have a Unicode-savvy regular expression standard class
My second major use of Perl is just another form of parsing: sorting data
into categories using *associative arrays*. It's wonderful to be able to
fly down a list that looks something like:
"Chinese,Spanish,Spanish,French,Spanish,Chinese,Tagalog,Spanish..." and be
able to say basically
$LanguageArray{$language}++;
and have it automatically declare the whole array, then create a new array
element each time it encounters a language in the list for the first time,
initialize that element to zero automatically, then increment the value
each time it sees that language mentioned again. Put a regular expression
above this line that tells it in one line how to parse the data (comma
delimited in this case), put the whole thing in one of Perl's "automatic"
WHILE loops, then this one line counts the number of occurances of each
unique language found regardless of how many different languages are
mentioned and how many times and in what order.
It's amazing how easy it is with Perl. Three or four short, simple,
bug-free lines that I use over and over again (which servers hit my site
the most?, which pages refer the most hits to me and how many?, which
products do people want the most?, what are the busiest hours for my site?,
etc.)
I'm certain the same task could be accomplished in Java (with some extra
overhead code, again, which doesn't bother me), but I don't know how to do
it in the simplest possible way. (Since Java isn't available yet for any
machine I own, I can't actually experiment with it myself.) It does seem to
me, though, that if this data sorting type of parsing can be done simply
(with the HashTable class, perhaps), then it would be a good idea to show
CGI programmers how to do it with Java. If it's not clean and simple and
easy to do with Java, could a standard class be created that would change
that?
What about what other people do in their CGI scripts with Perl? How easy is
it to do in Java, and could it be made easier without hanging all kinds of
special-purpose junk all over Java like ornaments on a Christmas tree.
It would be great if we had a FAQ showing the top ten things people do with
Perl in CGI scripts and how to do them simply and elegantly with Java. (The
process of creating such a list might point out an area where Java could
stand to be strengthened a bit, perhaps with an addition of a class to its
standard library.)
It would also be nice to have a bit of room on one of Sun's servers to
serve as a library of routines useful to web programmers both for CGI and
for applets. Some CGI ideas include an HTMLFormProcessor class which parses
the input from a form into an array of name/value pairs, a counter for
counting hits on a site (called from your HTML using "server side
includes"), an HTML3Table class that let's you build custom tables such as
invoices on the fly in response to customer input, etc. On the applet side,
we should have a bunch of templates that let people plug a few components
together to create basic applets. If people discover that they can put an
interesting applet together and have it up and running in minutes, Java's
popularity will soar.
I know some people don't want the extra competition from lots of new Java
programmers, but being experts in an obscure language won't get us very
far. In order for our expertise to be worth something, Java has to
flourish, and since I think webmasters are the key to that (to begin with)
I think the Java team should do what they can to get them doing all of
their web work in Java, not just their applets.
__Glen__
Glen.Perkins@NativeGuide.com
http://www.NativeGuide.com
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com