in reply to The REAL reason for why they choose PHP over Perl.

Two parts to this question:

Why use PHP over Perl for webpage design?

I use to do Perl CGI scripting, but switched to PHP because PHP was designed for webpage use. Originally, PHP was actually a Perl script (which is why both languages look so similar and why learning PHP isn't hard if you know Perl).

However, when I do non-webpage stuff, I still use Perl, and there are many times when I use Perl CGI scripting because the page I'm generating has so little static HTML code in it.

As others pointed out, PHP has a lot of functions for webpage design. It has built in functions to filter out "dangerous" text from HTML code, and there is quite a bit of very popular software built via PHP. (Mantis BT, Joomla, most Blogging software, etc.).

However, once you've stopped working with static webpages, Perl is a much more powerful language. I don't know of anyone who uses PHP for non-webpage tasks even though PHP can be executed directly from the command line.

Part II: Isn't Perl out of date and no one is using it anymore?

I blame the Python people for that one. I think Python people spend more time denigrating Perl than actually coding. Quite venimous stuff. According to them, Perl is impossible to read, it's not object oriented, it has too many operators, it's confusing, etc.

I only worked on Python once, and it was basically putting a few lines in a Python script. I spent three hours on the task: Five minutes of writing the code, and then 2 hours and 55 minutes trying to figure out what Python was whining about.

Seems like I committed the mortal sin of indenting the code with a tab instead of eight spaces. You see, Python uses indents to tell it which lines belong to which blocks of code instead of using curly brackets. A "feature" according to Python people. I haven't touched it since.

I am learning Ruby which is very similar to Python. It is an interesting language, but not that well supported yet. However, Ruby on Rails is something that I believe is going to make a big dent in the PHP coding segment and is something every PHP coder should be learning.

The problem with PHP is that it is extremely difficult to maintain in large sites. Your code is scattered all over the place, and gets hard to trace. Ruby on Rails takes care of this problem by providing a framework where the code and the HTML are separated. Also separated out are all the database functionality.

As a bonus, Ruby (like Perl and Python, but not PHP) is a useful right on the command line. And, unlike Python, it isn't dependent upon the correct whitespacing. My big complaint is that it doesn't use curly braces. Instead, it uses the beginning block's keyword and the word end to mark your blocks, so VI's showmatch mode doesn't work.

  • Comment on Re: The REAL reason for why they choose PHP over Perl.

Replies are listed 'Best First'.
Re^2: The REAL reason for why they choose PHP over Perl.
by Anonymous Monk on Jun 23, 2006 at 17:19 UTC
    I blame the Python people for that one. I think Python people spend more time denigrating Perl than actually coding. Quite venimous stuff. According to them, Perl is impossible to read, it's not object oriented, it has too many operators, it's confusing, etc.

    I don't. Much of their arguments are legitimate, if you care about the things they complain about.

    Perl *is* a large, complex language; that's a statement of fact, not opinion. I once counted over 200 function call formats in perlfunc; that's a lot for the base language. What's more, each function call can be called in one of three contexts: and lots of people don't understand context right away. You have to memorize each function twice; what it does in scalar context, and what it does in list context, and if they are different or not.

    Perl does a lot automatically, in a lot of different situations, and until you memorize what shortcuts perl is taking, you won't know what it's really doing. Even experts here on perlmonks run code through B:Deparse to try to make sense of what's really happening with strange code.

    Seems like I committed the mortal sin of indenting the code with a tab instead of eight spaces. You see, Python uses indents to tell it which lines belong to which blocks of code instead of using curly brackets. A "feature" according to Python people. I haven't touched it since.

    Every language has it's "rookie mistakes". A long time ago, when I was first trying to learn perl, I wasted several hours trying to figure out why a simple pattern match wouldn't work. Turned out I was using ~= where I should have been using =~ : I'd never used composite operators before, and kept reading over the typo. I nearly gave up on Perl then, too.

    Python's forced indentation has a purpose; it eliminates indentation errors (which can be annoying to track down on your own), and it ensures that your code is indented in a readable format.

    I've wasted a lot of time over the years, in C and in Perl, running a search for a {, % match it, try to figure out if that's what it should match, decide it is, go on to the next match, iterate. I've actually started commenting end braces whenever I have to maintain code; not only does it give a bit more explanation as to what an ugly off-screen construct seems to do, it helps me resolve the painful "does this brace match what it should match?" question. Looking back on those wasted hours over the years, a little "use tabs for indentation" rule just doesn't bother me that much.

    It also neatly solves another problem; pretty printing. If some wingnut formatted Perl inconsistantly (2 column indent half the time, 4 the next, 8 the next), you've got to parse the entire language just to indent the code. Perltidy does a good job with a horribly complicated language ("only perl can Parse perl"), but it didn't exist for years, and took a long time to write.

    With tab indents, you just change the size of a tabstop. A ten year old can write a "tab to space" converter.

    Perl's philsophy is just different than Python's. Perl people tend to focus on initial code development: the perl motto is "there's More than One Way to Do it". Python people tend to focus on maintainance -- something more like "There's One Right Way to Do It: strive to find it".

    Depending on whether your do more coding or more maintenance, you may prefer one over the other...