Diary of a Web Developer: Perl, Python, and PHP. Required knowledge.
note: This is not a contest.
This post is about tools in the web developer’s toolbox. This post is the sort of post that I wish I’d seen when I first got into web development. This post is meant to describe the tools in your toolbox, and their use within the context of the web.
Perl
Background
Perl’s our golden oldie. Released in 1987, it contains functionality found in AWK, C, Lisp, shell scripting, et al. It expanded rapidly from 1.0, gaining improved regular expression support in Perl 2 (1988), and then support for binary data streams with Perl 3 (1989).
Today, Perl has reached version 5.1 (2007), and has influenced an number of succeeding languages (such as PHP, Python, Ruby, etc.). It’s success can be accredited to trends in software development in which hardware costs were falling drastically, and programmers became more valuable. Corporate focus shifted from CPU-efficient C or Fortran to programmer-efficient Perl.
You can learn more about its history on Wikipedia’s Perl page.
How it works
Perl is an interpreted Language*, and when a Perl program is run, the following occurs:
- The perl interpreter is loaded
- The program is compiled by the interpreter
- The program is executed
This execution pattern benefits Perl (opposed to compiled languages like C/C++) because it delivers a lot of flexibility to the code. Perl is platform-independent, smaller, and easier to debug. Hooray for Perl!
*actually, Perl compiled to virtual machine code, then later interpreted at runtime to native code, read about interpreted language here
Recommended Usage
Described as a ‘swiss army chainsaw’, Perl is a powerful and adaptable tool. That said, it’s more than 20 years old, and the syntax looks like a monkey ran across a keyboard. At the time, it was secure, less awkward, and popular. Today, it competes with Python for dominance (and ain’t doing well).
Reach for Perl under these conditions:
- Memory use is critical
- Low IO overhead is required (i.e. – many, many text files are being parsed)
O’Reilly’s Perl.com delivers an excellent introduction to Perl for non-programmers. Check it out.
Python
Background
If Perl’s the golden oldie, then Python is the orderly math professor. Released in 1991 (almost old enough to buy a pack of smokes), version 0.9.0 delivered a language capable of class inheritance, exception handling, functions, and a handful of core datatypes. Also, this release brought with it a module system, which its Benevolent Dictator for Life deemed a ‘major programming unit’.
1994 brought with it comp.lang.python (considered a major milestone in userbase growth), version 1.0, and a handful of programming tools that a Lisp programmer dearly missed, and had hacked into Python.
Python can credit its success to the variety of programming philosophies it embraces. It’s a very high level language (closer to English than Assembly), and it supports a variety of programming styles (OO, structured, functional). It’s made to be extended (remember the module system?), leaving us with a small core langauge and a large standard library. After years of scarring with Perl, programmers felt Python’s kindred rejection of exuberant syntax.
The latest release is version 2.5.2 (2008), and you can find it behind Zope’s application server, Youtube, a variety of Google Apps, and NASA software.
In a very interesting turn of events, Python devs are breaking backward compatibility to deliver Python 3.0/Python 3000/Py3K. Here’s a Google TechTalk on the topic, check it out.
You can learn more about its history on Wikipedia’s Python page.)
How it works
Python is another semi-interpreted language. Here’s what happens when you run a python script (using sample.py):
- Python checks for sample.pyc
- Python checks if sample.py is newer than sample.pyc (if it exists)
- If that doesn’t exist, Python precompiles sample.py, storing a byte-code version as sample.pyc
- Python interprets & executes sample.pyc
Like Perl, this modified interpretation allows Python to be platform-independent, small in size, and easier to debug than compiled languages.
Recommended Usage
While a lot of programmers report ‘substantial productivity gains’ and ‘feel the language encourages higher-quality development’, those are emotional issues, and you need to deal with those on your own time.
Reach for Python under these conditions:
- You need something that processes quickly (but isn’t memory intensive)
- On the average, Python and Perl are neck & neck here. If you have more experience w/Perl, go for Perl. If you need something readable, go for Python.
- You have an OOP OCD
- You don’t know Perl, and you have some hefty processing to do (that isn’t memory intensive)
- You’re making the step from static HTML to dynamic web pages cough, and you have a CS degree
PHP
Background
PHP’s a n00b-friendly cockroach (I’ve been developing in it since files ended in .php3). It’s a scripting language that is general in purpose, widely accessible, and very popular. PHP is the most frequently installed Apache module, and is used on over 20 million web sites.
It began in 1994 as a series of CGI binaries written in C called Personal Home Page. Today, it’s managed by The PHP Group, and sports a userbase that is more than 5 times that of Perl. PHP3 (1998) brought a rewritten parser, and in a fit of recursive initialism, a name change to PHP: Hypertext Preprocessor. Further developments in the core produced the Zend Engine, and along with it, PHP4 (2000).
Today, PHP5 (2004) gives us reasonable OOP functionality, PHP Data Objects, and XML parsing. Additionally, PHP lacks finesse. Just sayin’.
If you want to learn more about the history of PHP, check out Wikipedia’s PHP page.
How it works
PHP bridges the gap between programmers and underlying server applications by providing an accessible interface into their functionality. This usually takes place on a web server, and involves web page generation.
It’s focus is on robustness and simplicity, and not on expressiveness or modularity.
Here’s what happens when you run a PHP script (ex. script.php):
- A server connection is opened (usually by a web browser), ex. http://somedomain.com/script.php
- Apache notices that you’re requesting script.php, and calls the appropriate handler (usually mod-php)
- PHP loads the entire script.php into memory, and proceeds to register vars & functions
- PHP interprets the script, executing it on the fly
- Output, if any, is flushed from the buffer as it arrives
Recommended Usage
It’s easy to use, and has a lot of functionality at your fingertips. It’ll get you 80% of your way w/out a hitch. The other 20% uses hacked functionality from other languages.
Reach for PHP when:
- You’re making the step from static HTML to dynamic web pages, and you have a business degree
- You need something exceedingly simple, and web-based (like a single page e-mail form)
- You don’t know Perl or Python, and you’re generating web pages
- You want the comforting warmth of a gigantic and opinionated development community that knows as much as you do
Summary & Conclusions
Only a programmer who’s mastered Perl, Python, PHP, and languages beyond would be able to make an objective decision about which tool is best for which job. There’s such a huge variety of competence and application, that it’s hardly worth exploring.
Therefore, the relevant objective here is to learn. Syntax changes, but logic follows you from language to language.
Learn to use all of them. The less pigeonholed you are in any particular language, the more accurately you can determine the best tool for the job.
Get started
Related Links
Comments
Comments closed for this article.
Damien
Jul 28, 09:47 AM #
Ah, how I wish I’d read this a few years ago. Here I am developing a project in PHP, wishing I was doing it in Python. If I might suggest another reason to use PHP over Perl or Python: if you’re developing for use on a hosting service where you have no control over the installed languages, PHP is probably the best choice because it’s installed in more places.
Pete K
Jul 28, 10:06 AM #
It’s true. Though if I rented a toolbox that only contained screwdrivers, I’d be pretty pissed, and look for a new toolbox.
I’m working on moving my site over to Slicehost. They’re well-documented, and you have a huge degree of freedom, Check them out
It’s not for beginners, though. Being comfortable w/command-line traversal is a must.