Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Python as replacement for PHP? (http://www.velocityreviews.com/forums/t328934-python-as-replacement-for-php.html)

Erik Johnson 02-27-2004 08:50 PM

Python as replacement for PHP?
 
This is somewhat a NEWBIE question...

My company maintains a small RDBS driven website. We currently generate
HTML using PHP. I've hacked a bit in Python, and generally think it is a
rather cool language. I've done Perl and like it, there are a few features
of PHP I like but overall am not too excited about it. I have found PHP's
strtotime() function to be quite flexible and handy and we make liberal use
of it.

I have not yet really "dug-in" to Python - I have dabbled and hacked a
bit. I am advocating considering switching to Python for a number of
reasons:

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.
3) Python's interactive interpreter makes it easy to try things out.
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).
6) All the other standard evangeslistic points about why Python is
better than <your favorite language here>, some of which may be valid to us,
some probably not. To those that have used PHP: what am I potentially losing
that Python really can't replace?

So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points: (NOT Python evangelism please: I've already heard most of it, I've
espoused a pretty good dose myself - frankly, I'm willing to buy most of it,
but I've got a serious business decision to make here).

1) PHP seems to have a pretty good integration/driver with PostgreSQL.
If we were to switch to Python, what modules/drivers are available to talk
to PosgreSQL and is it as functional as PHP's support?

2) Is there a way to have our cake and eat it too? That is, rather than
being forced to ride one horse or another, can I ride both horses at once:
is there a way to integrate PHP and Python such that I could call PHP
functions from a Python script? I know you can always make system calls, and
it probably wouldn't be that difficult to call an external PHP script and
slurp up it's output from STDOUT, but my impression is that this is a pretty
expensive thing to do (relatively) compared to generating HTML from a single
script invocation. I'm asking if there exists some sort of single-process
integration (e.g., something akin to Java's "native" interface where a
program can schlep data back and forth between a Java environment and
"native" C)?

3) Does Python have an analog to strtotime()? (For those not familiar
with that function, it converts a wide range of date formats as string into
time_t value. Can handle things like "now", "+24 hours", "-3 days",
"yesterday 06:00PM MST", "January 23, 2004", "2004-02-26 18:00:00 -07",
etc.)

4) I am vaguely aware of Apache's modpython. We are currently running
apache, but I'm real green when it comes to configuring/running/managing
Apache. I don't really understand what all modpython does for me. Generally
allows Apache to foist off an HTTP request on a Python script to handle I
assume, but maybe some kind soul can better inform me about what all
modpython really does for me?

5) A PHP script can freely jump in and out of static HTML and script
code with <?php ?> tags. This is sometimes handy. Can you do the same thing
with Python?

6) Debugging: I'm aware there is a debugger for Python - I haven't
really used it. Maybe there is a better way to do this using PHP, but right
now when a PHP script isn't working right, I'm reduced to print statements
and just re-running the script. Do you know a better way to do this in PHP?
If I were doing things in Python, is there an easy way to generate an HTTP
request from my browser, but stop the generating script and analyze it in a
Python debugger?

7) This goes back to #2, but we are looking at purchasing a PHP graphing
package: http://www.aditus.nu/jpgraph/ If we could easily call PHP from
within Python, then I guess that is a no brainer: we can use the PHP
package. If not, then we are left answering the quesiton, can we call it as
a forked process, and if so, is that too expensive? Do you know of
comparable packages for Python?


I think that's it for now. Thank you for taking the time to read my post
and many thanks in advance to anyone who would be so kind as to reply.
(direct response to ej at wellkeeper dot com greatly appreciated).

-ej



Bart Nessux 02-27-2004 09:08 PM

Re: Python as replacement for PHP?
 
Erik Johnson wrote:
> This is somewhat a NEWBIE question...
>
> My company maintains a small RDBS driven website. We currently generate
> HTML using PHP. I've hacked a bit in Python, and generally think it is a
> rather cool language. I've done Perl and like it, there are a few features
> of PHP I like but overall am not too excited about it. I have found PHP's
> strtotime() function to be quite flexible and handy and we make liberal use
> of it.
> 6) All the other standard evangeslistic points about why Python is
> better than <your favorite language here>, some of which may be valid to us,
> some probably not. To those that have used PHP: what am I potentially losing
> that Python really can't replace?
>
> So, I'm hoping there are some people out there that actually have some
> expereience with both Python & PHP and can give me some solid, informed
> advice about PHP vs. Python, in general and particularly on the following
> points: (NOT Python evangelism please: I've already heard most of it, I've
> espoused a pretty good dose myself - frankly, I'm willing to buy most of it,
> but I've got a serious business decision to make here).


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.

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. We use Python & C for backend processing, systems
administration and other general programming tasks, but the front-end
(the Websites) are pure PHP.



Phil Roberts 02-27-2004 09:12 PM

Re: Python as replacement for PHP?
 
With total disregard for any kind of safety measures "Erik
Johnson" <ej.at.wellkeeper@dot.com> leapt forth and uttered:

> 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?
>


SimpleTest: http://www.lastcraft.com/simple_test.php
PHPUnit (1):http://www.students.cs.uu.nl/people/voostind/index.php?
page=software
PHPUnit (2):http://pear.php.net/package/PHPUnit
PHPUnit (3):http://phpunit.sourceforge.net/

Having three test suites all called PHPUnit is a tad confusing...


--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/

Skip Montanaro 02-27-2004 09:20 PM

Re: Python as replacement for PHP?
 

Erik> 1) PHP seems to have a pretty good integration/driver with
Erik> PostgreSQL. If we were to switch to Python, what
Erik> modules/drivers are available to talk to PosgreSQL and is it as
Erik> functional as PHP's support?

I use psycopg and like it. There are a couple others as well.

Erik> 3) Does Python have an analog to strtotime()? (For those not
Erik> familiar with that function, it converts a wide range of date
Erik> formats as string into time_t value. Can handle things like
Erik> "now", "+24 hours", "-3 days", "yesterday 06:00PM MST",
Erik> "January 23, 2004", "2004-02-26 18:00:00 -07", etc.)

Marc-Andre Lemburg's mxDateTime might be the closest you'll get to such wide
ranging formats.

Erik> 4) I am vaguely aware of Apache's modpython. We are currently
Erik> running apache, but I'm real green when it comes to
Erik> configuring/running/managing Apache. I don't really understand
Erik> what all modpython does for me. Generally allows Apache to
Erik> foist off an HTTP request on a Python script to handle I
Erik> assume, but maybe some kind soul can better inform me about
Erik> what all modpython really does for me?

It essentially avoids process creation and Python startup overhead. Both
can be significant performance barriers on heavily loaded systems.

Erik> 5) A PHP script can freely jump in and out of static HTML and
Erik> script code with <?php ?> tags. This is sometimes handy. Can
Erik> you do the same thing with Python?

There are lots of different Python-based templating systems. I like
Quixote. It's roughly the inverse of the way most systems do the
HTML/<language> mind-meld. Instead of Python-in-HTML it's HTML-in-Python.
There are other systems with which I am not aware. Cheetah and PSP come to
mind.

Erik> 6) Debugging: I'm aware there is a debugger for Python - I haven't
Erik> really used it. Maybe there is a better way to do this using
Erik> PHP, but right now when a PHP script isn't working right, I'm
Erik> reduced to print statements and just re-running the script. Do
Erik> you know a better way to do this in PHP? If I were doing
Erik> things in Python, is there an easy way to generate an HTTP
Erik> request from my browser, but stop the generating script and
Erik> analyze it in a Python debugger?

Inserting print statements is a pretty common debugging technique in Python
as well. Also, take a look at the cgitb module.

Skip


CountScubula 02-27-2004 09:21 PM

Re: Python as replacement for PHP?
 
"Erik Johnson" <ej.at.wellkeeper@dot.com> wrote in message
news:403fa54b@news.zianet.com...
> This is somewhat a NEWBIE question...
> (snip)
> I have not yet really "dug-in" to Python - I have dabbled and hacked a
> bit. I am advocating considering switching to Python for a number of
> reasons:
>
> 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.
> 3) Python's interactive interpreter makes it easy to try things

out.
> 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).
> 6) All the other standard evangeslistic points about why Python is
> better than <your favorite language here>, some of which may be valid to

us,
> some probably not. To those that have used PHP: what am I potentially

losing
> that Python really can't replace?
>
> (snip)
>
> -ej
>
>



You should use what is best for you, but trying to settle on one laguage for
everthing is not a good idea, you will end uplocking yourself into more code
than you need sometimes.

Python is gread for server stuff, and GUI stuff, but for dynamic
intergration of html/script, PHP wins hands down.

Now I also use PHP for everything else (except GUI stuff) on servers, almost
all of my shell scripts are in php, along with autoresponders, mail filters,
data backup servers, etc..

But again, use what is quick/fast/simple to implment for you. I use to use
perl for everthing under the sun, then slowly moved to php, not becouse it
was cool, but rather easier to set up, and with added functions designed for
dynamic site ingration.

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, PHP was design specificly for dynamic/integration of web pages.

Ok, I'm done now.

--
Mike Bradley
http://www.gzentools.com -- free online php tools



Dave Brueck 02-27-2004 09:23 PM

Re: Python as replacement for PHP?
 
Bart wrote:
> Erik Johnson wrote:
> > This is somewhat a NEWBIE question...
> >
> > My company maintains a small RDBS driven website. We currently generate
> > HTML using PHP. I've hacked a bit in Python, and generally think it is a
> > rather cool language. I've done Perl and like it, there are a few features
> > of PHP I like but overall am not too excited about it. I have found PHP's
> > strtotime() function to be quite flexible and handy and we make liberal use
> > of it.
> > 6) All the other standard evangeslistic points about why Python is
> > better than <your favorite language here>, some of which may be valid to

us,
> > some probably not. To those that have used PHP: what am I potentially

losing
> > that Python really can't replace?
> >
> > So, I'm hoping there are some people out there that actually have some
> > expereience with both Python & PHP and can give me some solid, informed
> > advice about PHP vs. Python, in general and particularly on the following
> > points: (NOT Python evangelism please: I've already heard most of it, I've
> > espoused a pretty good dose myself - frankly, I'm willing to buy most of

it,
> > but I've got a serious business decision to make here).

>
> 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.
>
> 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.


What on earth?! Each is entitled to his or her own opinion, but this is a bit
over the top. The OP would do well to search the Google archives as this topic
has come up many times, and there are many who disagree with the above opinion.
Even if in the end the OP decided to stick with PHP (personally I wouldn't),
considering Python definitely does _not_ border on stupidity.

-Dave



Bart Nessux 02-27-2004 11:12 PM

Re: Python as replacement for PHP?
 
Dave Brueck wrote:

> Bart wrote:
>> Erik Johnson wrote:
>> > This is somewhat a NEWBIE question...
>> >
>> > My company maintains a small RDBS driven website. We currently
>> > generate
>> > HTML using PHP. I've hacked a bit in Python, and generally think it is
>> > a rather cool language. I've done Perl and like it, there are a few
>> > features of PHP I like but overall am not too excited about it. I have
>> > found PHP's strtotime() function to be quite flexible and handy and we
>> > make liberal use of it.
>> > 6) All the other standard evangeslistic points about why Python
>> > is
>> > better than <your favorite language here>, some of which may be valid
>> > to

> us,
>> > some probably not. To those that have used PHP: what am I potentially

> losing
>> > that Python really can't replace?
>> >
>> > So, I'm hoping there are some people out there that actually have
>> > some
>> > expereience with both Python & PHP and can give me some solid, informed
>> > advice about PHP vs. Python, in general and particularly on the
>> > following points: (NOT Python evangelism please: I've already heard
>> > most of it, I've espoused a pretty good dose myself - frankly, I'm
>> > willing to buy most of

> it,
>> > but I've got a serious business decision to make here).

>>
>> 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.
>>
>> 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.

>
> What on earth?! Each is entitled to his or her own opinion, but this is a
> bit over the top. The OP would do well to search the Google archives as
> this topic has come up many times, and there are many who disagree with
> the above opinion. Even if in the end the OP decided to stick with PHP
> (personally I wouldn't), considering Python definitely does _not_ border
> on stupidity.
>
> -Dave


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.

Irmen de Jong 02-27-2004 11:20 PM

Re: Python as replacement for PHP?
 
Bart Nessux wrote:

> 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.


WTF??

--Irmen

Dave Brueck 02-28-2004 12:03 AM

Re: Python as replacement for PHP?
 
Bart wrote:
> Dave Brueck wrote:
>
> > Bart wrote:
> >> Erik Johnson wrote:

[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. PHP claims to be
> >> a general-purpose language, but I do not know anyone who uses it for
> >> anything other than dynamic Web programming.
> >>
> >> 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.

> >
> > What on earth?! Each is entitled to his or her own opinion, but this is a
> > bit over the top. The OP would do well to search the Google archives as
> > this topic has come up many times, and there are many who disagree with
> > the above opinion. Even if in the end the OP decided to stick with PHP
> > (personally I wouldn't), considering Python definitely does _not_ border
> > on stupidity.
> >
> > -Dave

>
> 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???


Specifically which Python templating language(s) have you tried and found to be
"tedious and difficult" to use? Why is it that some people, knowing both PHP
and Python, opt for Python? It's gotta be something more than their own
stupidity. :)

ISTM you're way overstating the gap, if there is one in the general sense. It's
trivial to think of cases where PHP would be the "right" choice and others
where Python would be the "right" choice, so it's hard to put much stock in any
claim that it's so black-and-white, especially when you know so little of the
OP's requirements. Is it one of those "nobody ever got fired for buying IBM"
things? :) I can believe that for some DB driven dynamic web sites PHP would be
better suited, but *always*? No way.

> 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.


But why? What specifically is it about Python that makes one "stupid" for
considering it? (and does that mean that the many people who *do* use it - and
do so quite successfully - for such tasks are stupid?). Maybe I haven't seen
the light yet, but it's worked pretty well for me.

PHP has some good features, but it's certainly not perfect. Maybe it'd be okay
if it's were your first programming language, for example, but if you are an
experienced developer in other languages then PHP has its own bag of ...er...
surprises (did PHP5 finally fix the horrible copy-on-assignment "feature"?).

I have a friend who made a living for awhile as a "fireman" for PHP
projects-turned-disasters. In assessing the root causes of the disasters, much
of it was attributed to developer sloppiness or lack of experience, but a lot
of it went to language oddities such as weak OO facilities or the
over-encouragement of global variables. Overall the impression was that as PHP
projects grow in size, they tend to get unmanageable at a rate faster than
"normal" (compared to other languages). Anyway, I cite it only because it's a
web developer who has more experience than I do with PHP, but who avoids it in
his own projects due to specific experience with its problems.

There's just no validity to making the claim that the choice is so clear-cut.
Right tool for the job indeed!

-Dave



Roger Binns 02-28-2004 01:11 AM

Re: Python as replacement for PHP?
 
> So, I'm hoping there are some people out there that actually have some
> expereience with both Python & PHP and can give me some solid, informed
> advice about PHP vs. Python,


My approach is to use PHP with the Smarty templating system for the
web front end. All program logic and "heavy" lifting (and even
the light lifting) is done by a backend Python program accessed
via XML-RPC. That lets me use each language for what it is best
and most productive at.

Testing is easier since you can do it via XML-RPC.

Roger




All times are GMT. The time now is 07:58 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.