Re: Why PHP is so succesfull?
- From: seeWebInstead@xxxxxxxxxxxxxxxx (Robert Maas, http://tinyurl.com/uh3t)
- Date: Tue, 02 Dec 2008 02:03:41 -0800
Trent> ... server-side scripting in Java, which is possible, but it
Trent> sounds like a lot of hassle to me.
REM> Are you saying you've never tried it yourself because you perceive
REM> it to be "a lot of hassle" to even get started with the simplest
REM> starting program?
Trent> From: Trent <tr...@xxxxxxxxxxxxxxxxxx>
Trent> No, I've never written CGI scripts with Java myself. That's why I
Trent> made sure that I presented it as an impression rather than an
Trent> informed opinion. (I know Java, but I just haven't used it for CGI.)
OK, as I guessed and implied in my previous article.
Are there any features that are built into Java but not present in
your favorite CGI scripting language (I'm guessing Perl) which you
wish you could use for CGI scripts? If you refuse to use Java for
CGI then how do you deal with such a dilemma? Do you Greenspun such
a feature into Perl just to avoid using Java, or do you just not
write any CGI application that isn't easy in Perl?
Trent> ... I do have CGI scripts on my machine, just not Java ones.
OK, further confirming my guess.
REM> If so, have you seen my
REM> CGI hello-plus tutorial
REM> <http://www.rawbw.com/~rem/HelloPlus/hellos.html>
Trent> I hadn't before, but I have now.
So now that you've seen it, would you be willing to try simply
copying my first Hello World CGI java script (step 0) to your
machine and seeing if you can get it to work from external InterNet
connection? I'm curious whether my example works on systems other
than FreeBSD Unix. If it doesn't work as-is on your computer, I'm
curious what changes would be needed to make it work there.
REM> and if so does CGI/Java *still* seem like "a lot of hassle" just to
REM> get started?
Trent> Yes.
What hassle would be involved?
- Too much hassle to simply copy the various files needed for *my*
demo to your machine and compile the Java source?
<http://www.rawbw.com/~rem/HelloPlus/hellos.html#java0>
<http://www.rawbw.com/~rem/cgi-bin/show-h-java.cgi>
- Too much hassle if it doesn't work with the FreeBSD Unix
trampoline from CGI to Java
#! /bin/sh
/usr/local/jdk1.2.2/bin/java h
and you need to figure out how to adapt that trampoline to work
on your system?
- Too much trouble to edit the 'main' function in my demo to do
something other than just print "Hello World"?
- The step 0 works fine, and you can make trivial changes to 'main'
function to do other trivial stuff, but the somewhere among the
later steps 1 2 or 3
<http://www.rawbw.com/~rem/HelloPlus/hellos.html#java1>
<http://www.rawbw.com/~rem/cgi-bin/show-h1-java.cgi>
<http://www.rawbw.com/~rem/HelloPlus/hellos.html#java2>
<http://www.rawbw.com/~rem/cgi-bin/show-h2-java.cgi>
<http://www.rawbw.com/~rem/HelloPlus/hellos.html#java3>
<http://www.rawbw.com/~rem/cgi-bin/show-h3-java.cgi>
you can't figure out how to make my demo work on your system?
- You got all the way to step 3 working on your system, but looking
at my 'main' which does
HashMap hm = new HashMap();
and then populates it with key-value pairs from the URLencoded
form contents, and then I give examples of extracting the values
associated with particular keys from the HTML form submitted for
my toy CGI demo:
String fn = (String)(hm.get("firstname"));
String ln = (String)(hm.get("lastname"));
you can't figure out how to adapt those lines of code to get the
values associated with keys submitted from a Web form for *your*
attempt at a CGI/Java appliaction?
- You refuse to try *any* of that because you're so used to Perl
for CGI that you aren't willing to learn any new way to do CGI?
I.e. learning anything new is, to you, a "hassle"?
Have you seen these scientific results (below)?
<http://www.thebrainmatters.org/index.cfm?key=1.12.7>
(Skip to "learn new skills", very close to top)
<http://www.ahaf.org/alzheimers/about/risk/>
(Skip to "those who continue to learn", about 6 screens from top)
<http://www.sharpbrains.com/blog/2008/04/09/brain-health-and-alzheimers-prevention/>
(Skip to "brain exercise can prevent", about 9 screens from top;
"our culture makes people lazy", about 12 screens from top;
"piano teacher", about 15 screens from top)
REM> I'll admit Java has more boilerplate needed just to
REM> make a minimal program compared to most other languages,
Trent> Yes.
REM> but you
REM> can copy and paste that boilerplate from a template, such as from
REM> my sample/demo CGI applications, so it's just a lot of stuff to
REM> *see* in your CGI application, not any big bunch of stuff you have
REM> to write yourself from scratch just to get started.
Trent> So? I don't want to waste any more time than I have to,
How does the difference between copying a medium-sized boilerplate
for Perl from one CGI script to the next:
#!/usr/bin/perl
print << EOF
Content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3c.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
<title>Hello perl</title>
</head>
<body>
...Insert new code here...
</body>
</html>
EOF
and copying a somewhat larger boilerplate for Java from one CGI
script to the next, really matter? It's the same number of
keystrokes to do:
copy boil.perl newapp1.perl
edit newapp1.perl
f/put new code here/
vs.
copy boil.java newapp1.java
edit newapp1.java
f/put new code here/
Trent> especially when there are languages available that don't require
Trent> any of that boilerplate code.
Like what? A PERL script to generate proper HTTP/HTML output with:
Content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
<title>...</title>
etc. etc. is already 15 lines of boilerplate plus the one-line mark
where new code in the body is to be put. Even PHP needs some
boilerplate to switch back and forth between verbatim-HTML and
PHP-script mode, as well as most of that HTML boilerplate shown in
the PERL example that's the same in *any* CGI script that generates
proper HTML output. What CGI scripting does the DOCTYPE and meta
and title and <html><head>...</head></body>...</body></body> for
you automatically so you don't have to type that or copy it from a
boilerplate/template file every time you create a new script?
Trent> There's too much, as I said before, "syntactic clutter."
How is 15 lines of "syntactic clutter", copied from boil.perl for
each new script you want to build from scratch, or slightly fewer
lines copied from boil.php each time, any less painful then a
larger number of lines copied from boil.java or boil.lisp? The
keystrokes are virtually the same. And you're not carrying a deck
of Hollerith cards around for each program. You have computer files
and GUI text-editors or IDEs where the only text you need to see is
just the single window you're currently editing. And if seeing the
boilerplate clutter in your peripheral vision at top or bottom of
screen, it's trivial to include fifty blank lines before and after
the mark that says "insert new code here", so you *never* need to
see it while writing your new application. You see a blank edit
window with just that one non-blank insert-new-code line visible.
How can that possibly be "syntactic clutter" that you should even
care about?? Are you worried that 1k bytes of boilerplate copied to
each new CGI script you write will fill up your 10MB hard disk on
your Macintosh SE??
Trent> Compare all your System.out.println's with (untested):
Trent> #!/usr/bin/perl
Trent> print << EOF
Trent> Content-type: text/html
Trent>
Trent> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
Trent> "http://www.w3c.org/TR/html4/loose.dtd">
Trent> <html>
Trent> <head>
Trent> <meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
Trent> <title>Hello perl</title>
Trent> </head>
Trent> <body>
Trent> Hello world!
Trent> </body>
Trent> </html>
Trent> EOF
That's 15 lines of syntactic clutter, and one line that says "Hello world!".
Trent> Even without Perl's CGI add-ons, this is looking a lot
Trent> faster to write than your code.
Why would you need to write it? it's already been written, the 15
lines of Perl boilerplate, or the somewhat larger number of lines
of Java or Common Lisp boilerplate. You don't have to write it
again. You just copy it from where it's already been written.
Sheesh!!!
Trent> (Probably a lot faster to execute, too.)
If you want fast, use PHP, but only a system that runs PHP as an
Apache daemon that doesn't need to be re-started for each new
script that's requested from the net.
If you want *really* fast, set up a (one, 1, uno) persistent daemon
process for each class of server application, using a highly
efficient yet powerful runtime language with flawless automatic
garbage collection to avoid accumulating memory leaks over the very
long duration of the persistent daemon process. Common Lisp would
be the preferred choice, because it's faster than Java as well as
more powerful. If your application needs runtimes that are readily
available in Java but not in Common Lisp, then use Java instead.
Then use PHP for each instance of request from network, and have
the PHP script simply pass parameters to the appropriate persistent
daemon process and get back the result to simply pass back to the
client.
Now, I'm not saying that Java doesn't have its place in server
side scripting. But for small applications and simple scripts like
this one, it's way overkill.
For simple scripts, use PHP, unless you ever plan to make them more
complex, beyond the capabilites of PHP or even Perl, in which case
you would do better to **copy** (not re-key) the Java or Common
Lisp boilerplate and work from there from the start.
s/insert new code here/(print "Hello world")
s/insert new code here/print "Hello world";
s/insert new code here/system.Out.println("Hello world");
If that's too verbose in Java, add this (untested) to your personal boilerplate:
void static prl (string s) {system.Out.println(s); }
void static pr (string s) {system.Out.print(s); }
then to print with newline you edit:
s/insert new code here/prl("Hello world");
Note that in Common Lisp there's FORMAT which is a lot like C's PRINTF:
(format t "Hello world!~%I'd like to say something now:~%Bye bye!~%")
In a way that's nicer than how you need to do it in Java.
Of course if you need to generate HTML output, with <br> at line breaks,
it's a little more verbage in *any* language. But in Common Lisp
it's easy to define functions that convert a string from normal
STDIO output to HTML output, replacing each newline by <br>.
And you don't neet to put all your functions in your boilerplate.
You can put them in external loadable libraries, and just put
the (load "libr.lisp") or (load "libr.fasl") etc. in your boilerplate.
The key point is that anything whatsoever you need to do lots of
times, you can put in your bolerplate file or in separate loadable
libraries, so what you actually need to manually key into your new
CGI application is terse for almost *any* of these languages.
OH, there's one other reason Java might be a better choice than
Common Lisp for CGI applications: If you already have Java on your
machine, because MicroSoft ships Java with each new system, but you
don't have Common Lisp and haven't been able to find a good version
for your particular system configuration.
I've demolished your claim that the verbage/clutter/verbosity of
Java or Common Lisp is the killer in writing new CGI applications.
So what's your excuse for still using Perl for CGI and refusing to
even try Java or Common Lisp for CGI??
.
- Follow-Ups:
- Java for CGI [was: Why PHP is so succesfull?]
- From: Trent
- Java for CGI [was: Why PHP is so succesfull?]
- References:
- Re: Why PHP is so succesfull?
- From: Trent
- Re: Why PHP is so succesfull?
- Prev by Date: Re: Mergesort Vs Quicksort
- Next by Date: Re: Why PHP is so succesfull?
- Previous by thread: Re: Why PHP is so succesfull?
- Next by thread: Java for CGI [was: Why PHP is so succesfull?]
- Index(es):
Relevant Pages
|