[Tutor] Python vs. PHP

Erik Price erikprice@mac.com
Fri, 25 Jan 2002 00:17:35 -0500


On Thursday, January 24, 2002, at 04:57  PM, Pijus Virketis wrote:

> Looking around, I find what seem like two different kinds of dynamic
> webpages. Some are written in Perl (Slashcode) or Python (Yahoo search, 
> for
> instance), i.e. "proper" scripting languages, and others are done in
> ASP/PHP. I guess the former are CGI scripts, and the latter are active
> server pages. What are the relative merits of doing things one way or 
> the
> other? If I have a database, which I want to make accessible from the 
> web,
> and I can choose between Python or PHP, what should I consider on the
> design/performance level? Think in the broadest of terms, because I have
> little understanding of even the spectrum of options available between 
> good
> old static HTML and PHP, which I currently use and which is totaly 
> dynamic.

Pijus,

Let me say straight out that I am a novice to Python.  I am subscribed 
to this mailing list because I have read a bit about programming 
languages and would like to learn more about programming, Python seems 
to be a well-supported language for beginners.

So, without being able to compare Python to PHP, I would like to tell 
you a bit about PHP.  I started learning PHP two months ago and have 
been picking it up part-time.  Yet, I feel like I can do quite a bit 
with the PHP/MySQL combination.  PHP is a very very easy language to 
start off with, in my experience.  It's great because, when combined 
with HTML, it's like writing a program with a GUI from the get-go 
(admittedly a browser makes for a very limited GUI), so you get a great 
feeling that you're actually writing some USEFUL programs.  And PHP's 
other advantage is that it's really oriented toward making dynamic web 
pages.  Let's face it, besides a few folks who like to experiment for 
the sake of experimenting (the most noble kind of experimenting of all), 
no one uses PHP for much beyond dynamic web development.

Another big advantage of PHP is that the code is embedded in the HTML 
(or vice versa, doesn't really matter) -- you can literally jump in and 
out of "PHP mode" using <?php> open and closing tags.  This is really 
flexible, as you can write your entire page in HTML and add the PHP 
where it's needed, or you can write your entire page in PHP and include 
HTML where needed (or print it where needed).  PHP is designed to be 
extraordinarily compatible with MySQL and Apache (hence the common LAMP 
acronym for Linux, Apache, MySQL, and PHP = great combination), and 
features many custom functions for accessing MySQL.

In short, knowing NOTHING about web pages except very basic HTML, I 
started with PHP as my first programming language (except of course 
BASIC and a bit of bash scripting), and am well under way in developing 
a database-driven web application using LAMP -- learning Python is 
something that I am doing for myself, not for my boss.

If you are looking for a language that you can start banging out dynamic 
content via the web very easily and quickly, PHP is a great one.  But I 
would imagine that there is far more that you can do with Python, and a 
part of me wishes that I had started learning Python first and then 
moved on to PHP -- I have a difficult time thinking in terms of 
"traditional" programming because I am so accustomed to thinking about 
the "stateless" nature of web pages, where variables need to be passed 
from page to page.


Good luck,

Erik

PS: I'm sure that you can use PHP for things that it works well for 
(MySQL connectivity, display stuff), and Python for more advanced 
programs that you wish to execute on the server.  No need to choose one 
over the other!