Python as replacement for PHP?

C

Cameron Laird

On 2004-02-27 23:00:44 -0500, (e-mail address removed) (Cameron Laird) said:
.
[arguments against
positions *I* certainly
don't take]
.
.
All that said, PHP is a good language for a beginner. Lots of books
are available that approach the subject from just about any angle, it
is trivial to setup (you don't have to, you find some $5/mo provider to
do it for you, or you buy OS X,), and is so underfeatured that you
couldn't possibly be frightened by its syntax if it is one of the first
few languages you've seen. That doesn't mean it's a good language to
.
.
.
"OS X"? Panther, or Mac OS X 10.3, does build in an Apache--but
as near as I can tell, it's *not* one which includes PHP. PHP
has to be installed explicitly. Am I missing something?

I'm not ratifying the characterization of PHP as "underfeatured".
 
M

Matt Garrish

Cameron Laird said:
.
.
.
.
Let me get this straight: your preferred vehicle for XML
parsing is Perl regular expressions? That's ... well, it's
a different impression than I've ever gained from anyone
else with deep XML experience. It's sure not my first
instinct.

Not sure what the entire context of this thread is, but I get the impression
that you've misread what he was saying. XML parsing is an example of text
processing, and there are a number of Perl modules that can be used for that
task. Perl probably wouldn't be my first choice for parsing markup languages
(I'd personally use Omnimark), but it is all things to all people.

Matt
 
B

Bruno Desthuilliers

Bart said:
(snip)

(snip)

When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task.
(snip)

A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity.

(snip)

Bart, could you please back your (strong) assertions with at least one
argument ?

AFAIK, there is a whole lot of python tools for web developpement, and I
don't really see any evidence that one of the two languages is more or
less suited to this kind of task.

The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established
- there may be some specific libs not (currently) available in Python.

Bruno
 
W

Wilk

It's where php lacks for business decision.

When the application will grow up it will be time to have a clean
design, a standalone server and handle differents protocols. For this
python will be a good choice (look at zope, twistedmatrix, webware,
quixote...).

It's why i had to rewrite a lot of website from php to python. Now, with
delicious template like cheetah, i begin imediatly in python even if
it's overkill for little websites.

Even futur version of php tends to java. With python we have
already all the features of java.
Sorry, I disagree. As a business decision, it does border on stupidity. Why
contemplate doing something with Python that would be tedious and difficult
at best when PHP can do this task easily and quickly??? From a business
(read practical point of view) it's stupid. From a religious (Mac fanatic
like point of view), it makes sense.

The OP spoke of a DB driven dynamic Web site. One cannot think of such a
thing without naturally thinking of PHP... python should not even come to
mind for this task. Backend/server-side processing, sure, but not on the
frontend. Use the RIGHT tool for the job. Python isn't the right tool here.

lol !
 
S

SimonW

I've found that the server pages paradigm, used by PHP and ASP, to be
rather limiting when it comes to larger scale web applications. The
paradigm also lends itself to creating spaghetti code (and sites).
Python on the other hand, is quite capable of creating systems not bound
by the convential server page paradigm. It also has powerful facilities
for managing modules, classes and namespaces, which PHP lacks. These
things help out tremendously when it comes to maintenance. Unless PHP
has changed drastically in the last year or so, I believe these
assertions to still be correct.
I've been programming PHP for much longer than I have been using Python.
After cleansing my mind of the server pages style architecture forced
upon me by PHP, I re-found the fun I used to experience in web
programming. Python is perfect for the job. I've found mod-python a bit
of a chore, so I used twisted web for a while. I've now written my own
server, specifically for handling a REST style architecture. It took me
4 hours to write. It handles gzip encoding and basic authentication.
This is not a testament to my ability, but to the fluidity and power of
Python.
You provide no qualification for this statement. Your admonition to
"not even" consider other languages than PHP is bad advice, and springs
from your own stupidity and/or ignorance.


Regards,

Simon Wittber.
 
B

Bart Nessux

Bart, could you please back your (strong) assertions with at least one
argument ?

AFAIK, there is a whole lot of python tools for web developpement

The OP was comparing Python to PHP, not ZOPE to PHP. PHP by itself is a
natural Web programming language, Python is not. Google for dynamic DB
driven programming tools... how may PHP returns vs Python returns are
there?
The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established

That's exactly right. That's my point. I meant nothing more.
 
V

Valentino Volonghi aka Dialtone

In data Sat, 28 Feb 2004 12:46:13 -0500, Bart Nessux ha scritto:
The OP was comparing Python to PHP, not ZOPE to PHP. PHP by itself is a
natural Web programming language, Python is not. Google for dynamic DB
driven programming tools... how may PHP returns vs Python returns are
there?

Since he asked about how to use python for web purposes, one could expect
that he doesn't know what tools are needed to make python one of the best
web programming languages. Zope, Quixote, Cheetah and WebWare, Twisted
with Woven or Nevow (etc.) are all well known products in the python
community.
That's exactly right. That's my point. I meant nothing more.

<cite>
Sorry, I disagree. As a business decision, it does border on stupidity.
Why contemplate doing something with Python that would be tedious and
difficult at best when PHP can do this task easily and quickly??? From a
business (read practical point of view) it's stupid. From a religious (Mac
fanatic like point of view), it makes sense.
</cite>

Actually it seems you meant that a web solution using python would have
been both difficult and tedious...
 
B

Bob Ippolito

On 2004-02-27 23:00:44 -0500, (e-mail address removed) (Cameron Laird) said:
.
[arguments against
positions *I* certainly
don't take]
.
.
All that said, PHP is a good language for a beginner. Lots of books
are available that approach the subject from just about any angle, it
is trivial to setup (you don't have to, you find some $5/mo provider to
do it for you, or you buy OS X,), and is so underfeatured that you
couldn't possibly be frightened by its syntax if it is one of the first
few languages you've seen. That doesn't mean it's a good language to
.
.
.
"OS X"? Panther, or Mac OS X 10.3, does build in an Apache--but
as near as I can tell, it's *not* one which includes PHP. PHP
has to be installed explicitly. Am I missing something?

I'm not ratifying the characterization of PHP as "underfeatured".

By "installed explicitly", do you mean "turned on in httpd.conf"? You
may be right that pre-10.3 didn't include /usr/bin/php (I am not sure),
but mod_php has been standard (just not enabled by default) since at
least 10.1.

When I say grossly underfeatured, I mean the *language* not the *library*.

-bob
 
A

Andy Dingley

Let me get this straight: your preferred vehicle for XML
parsing is Perl regular expressions? That's ... well,

Rather more restrained a comment than I'd be capable of expressing ?
 
B

Bruno Desthuilliers

Bart said:
The OP was comparing Python to PHP, not ZOPE to PHP.
Neither was I. There are *many* much more web developpement tools in
Python than just Zope.
PHP by itself is a
natural Web programming language, Python is not.

<lol>
How should I understand 'natural' in this context ?
</lol>

More seriously : what does 'natural Web programming language' means ?
Google for dynamic DB
driven programming tools... how may PHP returns vs Python returns are
there?

And ? How does this make Python, I quote : "not even close to being
suited for this task."
That's exactly right. That's my point. I meant nothing more.

Ho yes you meant more. I still wait for any serious argument to back
your claims that "Python is not even close to being suited for this
task." and that "considering another language " (than PHP) "for this,
(...) borders on stupidity".

Bruno
 
P

Peter Maas

Bart said:
That's exactly right. That's my point. I meant nothing more.

That's ALL? No preference for specific PHP issues that makes you
choose/recommend it over Python? If youre "stupidity" posting has
anything to do with logic then I must conclude that you consider
everbody who doesn't use the de facto standard (choosing e.g. Linux
over Windows, Python over Perl) bordering on stupidity.

Strange, to say the least.

Mit freundlichen Gruessen,

Peter Maas
 
K

Keith Bowes

CAUTION: I'm replying as a non-Python programmer.
1) I think Python is cool.
2) We can do system administration type scripts (currently
implemented in Perl), web page generation (PHP), and (potentially)
client-side applications (including GUI's that make socket and/or external
HTTP requests) in one language.

You can do client-side apps in PHP too. Pass the -q option to the CGI
version or just use the CLI version.
GUI - PHP-GTK
Sockets - The socket extension or fsockopen() to treat it as a regular file.
3) Python's interactive interpreter makes it easy to try things out.

? Like the -r option?
4) PyUnit - we would like to develop a robust set of tests and be
able to do regression testing. I'm not aware of a JUnit/PyUnit analog in
PHP. Are you?
5) Python has better code support for complex native data types
(e.g., tuples, dictionaries, sequences, etc. and being able to write these
directly in a hierarchical structure rather than building them up piecewise
with function calls and assignments as in PHP).

In PHP, all these things are essentially arrays and that works fine.
Even the PHP developers say that classes are just syntactic sugar for
associative arrays (that'll change in PHP 5, though). So PHP is
procedural; there's nothing wrong with that.

Not to sound like I hate everything which isn't PHP. It's just that PHP
does have a wide range of functionality and is moving toward
command-line/administration capabilities, and is quite easy to learn if
you know other C-like languages. But if you think that Python better
serves your purpose, then you should use it. Surely, it would be
possible to write a strtotime() implementation in Python; someone may
have already done so.
 
P

Peter KERR

Often Python is the best tool for all the jobs there is to do. People
just fail to see that because, driven by prejudice, they opt for the
tool that can *only* do whatever the job is at the moment. That might
have been sensible 15 years ago, but the software landscape has
changed since.

and will change again before you're ready :-(
Use whatever you are happy with that does the job,
just do it so well that the next guy in your position
isn't tempted to rewrite it in his favorite language...
 
P

Peter Maas

CountScubula said:
You also need to look at what each language was desgined for, sure I can
write a dynamic web page in bash or korn, but why? Perl was written to do
large extraction and reporting of text files, Python was written as a server
language

I don't think so. It seems Python was written as a rapid development
language without a specific application range. That's an advantage
because you can get a lot of different jobs done very well. That's
a disadvantage because there's no no-brainer like "Python is for ...".

A family of marketing phrases comes into mind:

- Python is NOT for device drivers.
- Writing a device driver? Beware of Python!
- OS kernels? Don't even think of Python!
....

:)

Mit freundlichen Gruessen,

Peter Maas
 
D

David M. Wilson

Bart Nessux said:
When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.

Like everyone else who has replied, I seriously question how much
experience you have with the multitude of Python web environments
available. As an objective, point-by-point look at your specific
example of somewhere PHP is strong, here's my reply:

[PS: I still use PHP regularly, albeit only for quick unimportant
hacks that won't exist in 6 months]


- Nearly all the PHP code I have seen (including various large web
sites) fails to handle error conditions, and will run amok given a
down DB server, bad filesystem permissions, or bad inputs. I have had
personal experience, on more than one occasion, of an error condition
in someone else's PHP code causing a large amount of damage to a
dataset.

- The equivalent Python code will almost never do that. Thanks to the
religious throwing of exceptions, well written standard libraries, DB
adaptors, and so on, the worst Python code has a MUCH better chance of
getting stopped in it's tracks just as a fault occurs.

py> open("/tmp/foo","w").write(123)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: argument 1 must be string or read-only character buffer,
not int


[22:15:14] [cape:4:dw]$ php4 <<e
> <? fwrite(fopen('foo','w'), 123); ?>
> e
[22:15:16] [cape:5:dw]$ cat /tmp/foo
[22:15:17] [cape:6:dw]$

Can you tell me exactly what the PHP fwrite function did when I passed
it an integer? Can you tell me how many PHP programmers test
"(strlen($to_write) == fwrite($fp, $to_write))"?


- In the specific instance of database connectivity, Python is far
superior, in terms of intuitiveness, security, safety, and so on.
Python database APIs are built in a way that protects you by default.

- PHP provides no intuitive default support for many common DB
operations. Compare the following messes:

py> l = MySQLdb.connect()
py> c = l.cursor()
py> user_input = "%t%"
py> match_count = c.execute("SHOW DATABASES LIKE %s", ( user_input
))
py> print match_count, "matches:", [ x for x, in c ]
1 matches: ['test']


<? $s = mysql_connect();
$user_input = "%t%";
$query_sql = sprintf("SHOW DATABASES LIKE \"%s\"",
mysql_real_escape_string($user_input, $s));
$query = mysql_query($query_sql, $s);
$matches = array();
while ($row = mysql_fetch_array($query, MYSQL_NUM)) $matches[]=
$row[0];
echo sizeof($matches), " matches: ", var_export($matches, true);


Tell me, of these two popular examples of bad code in both languages,
which is the more intuitive to read, which is the more elegant to keep
secure, and which would you prefer to be reading, and modifying in 18
months time? [In this case, which was the quicker to create? The
Python example. The PHP counterpart has a syntax error somewhere, I
care not where.]

How many different ways can you dream up the same functionality in the
PHP example? (mysql_escape_string, <random_db_api>, etc.)

How likely is it that the developer you hire to take over development
of either snippet of code will understand the concept behind it? I
can't even think of another way of doing database query in Python,
without using the low-level interfaces, which is just insane.

We could bring the PHP ADODB, or many of the other numerous PHP APIs
for DB connectivity into the picture, but which of these are the
obvious choice, and officially endorsed?

How easy is it to improve on both these examples to add proper error
handling? Again, Python wins hands down for elegance, conciseness, and
obviousness.


- Python has a religious following of thousands, many of whom found
freedom through it's restraint, unified path, and downright beauty.
The result is a long tradition of structured, well written code.
Python has roots in academia, and started life with a defined purpose,
and a BDFL who knew what he was doing.

- PHP, "the web designer's ideal first language", started out life as
"a collection of perl scripts" (that says it all really), then ported
to C, then hacked and added to until it was the great swiss army
monolith that it is today. PHP has never had a clear, publically
documented development path, or indeed any form of structure or
organisation, past the menu system of PHP.net

PHP developers tend to have started life using Dreamweaver, happy to
accept the first solution to a problem that comes their way, and care
little about technical merit. Every person (including at the time,
myself) who I know that uses, or used PHP, did so because it allowed
them to make things look beautiful and dynamic very quickly.


- Python gurus, when asked how to make something work, will often
appear nasty and horrible, telling you you're doing entirely the wrong
thing and you should go back to the drawing board. Much like the hot
sting from a smack of a father's hand, this is good, not bad. It is
there to direct and discipline you, and improve the way you think.

- PHP gurus tend to be experienced web developers, they'll be able to
look flash and give you an answer on the spot, but that answer will
only further lead to the demise of any structure your coding ever had.



- Python tends to be slow, but slow compared to what? The laptop I
type this message on has a 2ghz processor. It cost less than £1000. It
is the cheapest laptop money can buy in the UK. I run Python scripts
on multi-gigabyte datasets on a daily basis on this machine. I have
never considered the scripts to be 'slow'.

- PHP is very light on CPU, memory, and so on. I earn a modest amount
for a 20 year old, even by Northern Ireland standards. I can't see how
I would ever need to resort to PHP because I couldn't afford the
hardware to run a complex Python-based site intended for viewing by
thousands.


Personally, I find the average PHP codebase to be akin to a television
station such as MTV: well presented, streamlined, professional
looking, but in terms of content, nothing but meaningless, mindless
shite. On the other hand, reading certain Python code is more like
reading a beautifully typeset hardback novel: black and white - ugly
to some, but functional, educational, structured, meaningful, etc,
etc.

What interests you more - earning money through thoughtless,
effortlessly produced rant-syntax that no-one will ever want to look
at again, or the daily challenge to produce something that will
perfectly fulfill it's intended function, at the cost of a little
time, a little brainpower, and a little discipline.

I could go on, but I think these points alone are the main reasons I
use Python. At the cost only of speed, it protects me, teaches me,
profits me, and inspires me to continue being the professional geek
that I am. :)


David.
 
P

Paul Rubin

Like everyone else who has replied, I seriously question how much
experience you have with the multitude of Python web environments
available.

The very existence of a "multitude" of Python web environments is a
serious shortcoming of Python as a PHP replacement. PHP comes with
one web environment, not a multitude, so you have just one manual to
read, not a multitude; one codebase to worry about keeping up with the
latest releases for, not a multitude, and so forth. You don't have to
check out and evaluate N different web environments and K different
database interface packages, and make sure they're all in sync with
each other whenever you update anything. PHP's web environment are
database integration right there for you the moment you install PHP.
- PHP provides no intuitive default support for many common DB
operations. Compare the following messes:

That's ok, Python has no default support at all, intuitive or
otherwise, for ANY db operations, common or not.
We could bring the PHP ADODB, or many of the other numerous PHP APIs
for DB connectivity into the picture, but which of these are the
obvious choice, and officially endorsed?

That's precisely the situation Python is in now!
- Python tends to be slow, but slow compared to what? The laptop I
type this message on has a 2ghz processor. It cost less than £1000.

Yes, but we're talking about server side applications, that can have
to support thousands of users simultaneously. They always want more
speed and rarely are found running on laptops.
- PHP is very light on CPU, memory, and so on. I earn a modest amount
for a 20 year old, even by Northern Ireland standards. I can't see how
I would ever need to resort to PHP because I couldn't afford the
hardware to run a complex Python-based site intended for viewing by
thousands.

The site that I worked on spent TWO MILLION U.S. DOLLARS on its web
server hardware. OK, it used Java servlets that are even slower than
Python, but you have to understand that there's a point after which
you can no longer pretend that hardware is free.
 
D

Dag Sunde

David M. Wilson said:
Bart Nessux said:
When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.

Like everyone else who has replied, I seriously question how much
experience you have with the multitude of Python web environments
available. As an objective, point-by-point look at your specific
example of somewhere PHP is strong, here's my reply:

[PS: I still use PHP regularly, albeit only for quick unimportant
hacks that won't exist in 6 months]

< a lot of brilliant points snipped />

ROFLMAO!

Wohoo!

Thisone is going to draw some heat, David!

(Not that I don't agree with you, though...
Python is probably the most beautiful
scripting language I've ever used).
 
J

JanC

Paul Rubin said:
The very existence of a "multitude" of Python web environments is a
serious shortcoming of Python as a PHP replacement. PHP comes with
one web environment, not a multitude, so you have just one manual to
read, not a multitude; one codebase to worry about keeping up with the
latest releases for, not a multitude, and so forth. You don't have to
check out and evaluate N different web environments and K different
database interface packages, and make sure they're all in sync with
each other whenever you update anything. PHP's web environment are
database integration right there for you the moment you install PHP.

You're sure about all that?

What's all this stuff then:
<http://pear.php.net/>
<http://smarty.php.net/>
<http://phptal.sourceforge.net/>
<http://rwfphp.multispan.com/>
<http://www.phpmvc.net/>
<http://www.dreammask.com/PHITE.php?sitesig=PT>

& more: <http://www.google.com/search?q=php+web+framework>
 
P

Paul Rubin

JanC said:

Looks like a bunch of PHP packages whose existence you can safely
ignore if the default stuff does what you need, as it does for most
users.

Sooner or later I hope there will be default web packages included
with Python, but until that happens, you have NO CHOICE but to go find
something on the net that might or might not fill your needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top