Well I was wondering which to use for my, um, web project. I really think perl is outdated, and php is ugly but most used. And then python is faster and easy to code, but hard to read. I know the basics of all three, but I'm wondering what you uber techies think is the best.
Perl isn't outdated. It's still actively developed, and new software is still written in it. It was, and still is, very good at text processing, and that's what most of Web development comes down to. The only "problem" with Perl is that it was designed as a replacement for half a dozen smaller Unix tools, so if you're not familiar with any of them, Perl has a lot of.. idiosyncrasies. But it's still plenty powerful and fairly consistent.
PHP is a mess. It's a bad clone of Perl shoehorned into C syntax. Almost everything about it is shoddily done, and it's pretty much too late to fix now. Its only benefit is that it saves you a few lines of httpd configuration if you need a speed boost. But quick one-page scripts can usually be CGI without any problems (and can be made persistent without much trouble), and big applications should be using some framework or other anyway.
Python is great. Use that if you don't already know Perl. CGI works fine, there's a mod_python if you really don't want any structure, there's Django if you want to build an app with a lot of stuff done for you out of the box, and there's Pylons if you want to build an app but like to tinker.
There's also Ruby, which is sort of a middle ground between Perl and Python. Haven't used it much, though. It has Rails, which is like Django (and which most web frameworks were inspired by), as well as a handful of others with different approaches.
And of course real men use C. And butterflies.
Perl - Slow, resource-heavy, for ad-hoc PHP-like execution of individual files and scripts, it requires Apache or another CGI-aware server. Differences between the Windows and Linux perl libraries cause problems (or they did back when I was messing with it).
Perl is
neither slow nor resource-heavy. In fact, it beats PHP in memory usage in most of those benchmarks, and its speed is equivalent on average.
I developed Perl on Windows for use on a Linux server for quite some time and never ran into any problems. Of course, I'd suggest just not developing Perl on Windows in the first place.
Wrapping a single Perl script to run as FastCGI for nginx or lighttpd is not difficult. This sort of thing is a minor concern in the first five minutes of development, but deployment is generally something you set up only once.
PHP - Not without its problems, easier to learn than Perl, easier to write bad and insecure code. Supports ad-hoc execution of individual scripts (CGI-like operation) in FastCGI mode.. supported by any server that supports FastCGI for better performance than Apache's mod_php or regular CGI.
Anything can run as FastCGI. It's entirely language-agnostic, and it will always be faster than CGI.
Python - Reportadly easy to learn, but tends to force the developer to treat the web application like a compiled application rather than a collection of scripts.. implies that CGI-like operation is not possible, though applications written in Python can be run as FastCGI, and thusly supported by nginx and other FastCGI aware servers.
CGI is also language-agnostic. It's just as easy to write CGI Python as it is to write CGI Perl. Your application is only an application if you write it as such—which you should.
Naturally I tend to prefer PHP because I can write an application like vBulletin, where different .php files, are called to perform different functions in the overall application..
Which renders the entire application loosely-coupled and harder to maintain for no gain. Most such PHP applications also end up with a bunch of files that something like general-script.php?actual_action=newreply (like the page I'm on right now, newreply.php?do=newreply), which is a cheap hack around the real routing system you'd get with any MVC framework.
To my knowledge, neither Perl nor Python's interpreter can be operated this way, so applications written in Perl or Python have to be self-contained FastCGI programs with their own webserver for which nginx can proxy requests to and from.
This is completely wrong, and you clearly have no idea how FastCGI works. There is no independent web server; the application needs only to have an event loop that checks a few environment variables instead of running once and exiting.
Here is a Perl CGI script:
Code:
#!/usr/bin/perl
use strict;
use warnings;
print "Content-type: text/plain\n\n";
print "Hello, world!\n";
Here is a Perl FastCGI script:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use FCGI;
while (FCGI::accept() >= 0) {
print "Content-type: text/plain\n\n";
print "Hello, world!\n";
}
You can easily write or find a wrapper script that will let you run Perl CGI without any modification to the original code.
This makes the use of Perl or Python for small simple CGI-like scripts, using the nginx (or any other FastCGI aware server), pointless.. in this case I'd write them as a compiled C++ program instead.
Yes, because writing a C++ application is clearly easier than using a 40-line FastCGI wrapper script you can find online. Or spending ten minutes to see if the latter is even feasible.