Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl vs. PHP

by nikos (Scribe)
on Aug 13, 2004 at 17:31 UTC ( #382763=perlmeditation: print w/ replies, xml ) Need Help??

Hi

It's so hard to see but it turns out employers prefer to use PHP for their new developments. Several times I was stuck thinking how to prove that Perl is the way to go.

My short list of facts:
1) Have you ever seen in your life a one-liner in PHP? ...no...I guess
2) Lot's of modules (CPAN). All of them well-organized and ready to go
3) Easy-to-use and implement tough things in a few lines of code. Number 3 in the list is close to Number 1... still
4) Imagine PHP embedded in HTML using a template engine... Common, how many time have you seen a php script in a separate file?
5) PHP is easier to learn and can be taught at high schools. Perl is much more complicated and requires more skills to start writing 'medium-level' scripts. That's why many people use it as they learned it at school. The last fact is common for beginners.
6) How do you write a regex in PHP? Perl?

I remember the good times when Perl was so popular and almost everyone from my friends who programmed used it for his challenging tasks and his everyday routine.

Any ideas, additions, corrections ... threatenings are welcome.

And remember ... Perl is GREAT !!!

Comment on Perl vs. PHP
Re: Perl vs. PHP
by dragonchild (Archbishop) on Aug 13, 2004 at 17:40 UTC
    See Re^3: Why can't mod_perl+Mason just work? for my response to this.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Thanks. Nice post. More tech-related additions to my post would be great to know. Thank you again!
Re: Perl vs. PHP
by perrin (Chancellor) on Aug 13, 2004 at 19:05 UTC
    Your PHP complaints are far too low-level. The big problem with PHP is that it has essentially no way to encapsulate things or share code safely. See this article for more.
      what about php5? they've added a nice class support.
        Classes are better, but they still have no namespaces. Everything is in one global namespace.
Re: Perl vs. PHP
by Juerd (Abbot) on Aug 13, 2004 at 19:54 UTC

    Mandatory link: http://tnx.nl/php.

    1) Ever seen a c one? 2) PHP'ers prefer to copy and paste. 3) easter_date(). 'nuff said. 4) often, thank $god. 5) Perl's easy enough to learn, but PHP is easy-er. I wonder why Ruby isn't more popular: very easy AND very powerful. 6) See above link. It depends on which features you need. Select your function carefully.

      1) Ever seen a c one?
      The International Obfuscated C Code Contest has a few. The most recent "best one-liner" is schweikh.c:
      main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return*t-42? +*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
Re: Perl vs. PHP
by superfrink (Curate) on Aug 14, 2004 at 06:49 UTC
    The $ , @ , % confuses people. I learned perl to maintain a script which contained " $$$foo ". Now it makes perfect sense (well maybe not the "foo" part which was the actual variable name) but at the time it was downright scary, that looks like it shouldn't even run. I still do PHP at work because they have a large code base but I plan to avoid it in the future. The following is a bit of a rant / ramble on why I've been turned away from PHP.

    Issues I've had with PHP in the past have cost time because of re-writing already production code after a minor PHP version upgrade. As far as I know the PHP answer to a security bug is to upgrade to the newest release and all of it's changed functions. My employer has re-used PHP code across dozens of sites. The upgrade cycle is a pain. Right now I only recall a couple examples.

    1. The mysql_connect() return value/type was changed so regexes on the result had to be modified. This was a small fix but a waste of time in my mind.
    2. File uploads: $_FILES[...]['name'] changed in php 4.3.7 to not include the full path to the file on the browser side, even though some browsers pass it in. I couldn't find reference to this in the Changelog, our customer phoned when he noticed a problem. I replaced the PHP file with a perl CGI script.

    Then there is the lack of namespace. I had created a form variable named 'file'. I accessed it via $_GET['file'] but that broke the site. The GET value overwrote the $GLOBALS['file'] array which held some paths used by the application. They look like they are different hash tables but there is shared data!

    In fact if you change the variable $file you've just changed the $GLOBALS['file'] as well. PHP fans will tell you to turn off the "register globals" setting but that will break existing code which was written before register globals existed. Note that inside a function $file will not touch $GLOBALS['file']. It's only in the main body of your script this conflicts. While on functions the "function" keyword is like "sub" in perl but note it's not case sensitive. Oh and hand-in-hand with that the names of functions you write are not case sensitve either. That's important when grepping code trying to find a function.

    PHP doesn't seem to have been build with modules in mind! You want zlib support? Recompile PHP. MySQL? Recompile. mcrypt? Recompile. GD graphics functions? Recompile. EXIF and PNG? Those are extra compiles too. TrueTypeFonts? Recompile. See the pattern here? Want to talk IMAP? Recompile.

    I just checked one server and PHP's ./configure line is 1478 characters long. Yes PHP supports loading .so files but come on 'use foo;' is so nice. On that note if your admin doesn't have a Perl module installed you can just put the source in your cgi-bin directory and "use" it like normal.

    On to error reporting. PHP has nothing like 'use strict;'. End of discussion. It's a pain. Also PHP has no way to declare a variable before using it. If you mistype a variable name it will be created for you. (The keyword 'var' is only used inside of classes AFAIK.) Oh that's not entirely true. Arrays can be defined with $foo = array(); which you should do because othewise foreach loops break in case you didn't have any data to push onto the array when you expected to. Please do note that error messages have improved very much since PHP 4.0.

    Function names seem all over the place like these array functions. Some have a prefex, some don't: array_push, array_pop, array_keys, sort, count, key.

    Compare this simple regex replace:
    $foo =~ s/^abc//;
    with the PHP version:
    $foo = preg_replace('/^abc/', '', $foo, 1);
    Don't forget the slashes are needed in that first function argument but not the second. I still don't know why. Good luck if you need to put backslashes in there because sometimes you need 2, 3 or 4 to escape it. I have backticked sed commands just to make regexes work in PHP.

    I never do recall how to pass or return things by reference. You need & in a few places and I think maybe a \ somewhere. PHP5 has supposedly changed this anyway.
      I used to work with PHP too, because it was so easy to start on at the first glance... What a mistake! My ol' perl codes I wrote back in 96 on perl 4/IRIX still run unmodified on perl5.8.6/slack, while I had to rework the php code I wrote back in 2000 3 times : from php3 to php4, from php4 to php4.2 (register_globals, anyone?), from php4.2 to php4.3 (mysql_... return values changed), and good luck, now there's php5! OK php is easy, quick and dirty, but the syntax is incoherent, the code is a mess, the whole thing is a pain. I'll surely rewrite all that mess using perl some day!
Re: Perl vs. PHP
by runrig (Abbot) on Aug 14, 2004 at 07:59 UTC
    Perl wins hands down :) (so are we done yet?) Uh-oh, uh, I want a recount...(I guess that's what happens when you start a fight at one int the morning) :-)
      According to the same Googlefight algorithm, "Dolphins are fish"!

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Perl vs. PHP
by jacques (Priest) on Aug 14, 2004 at 12:23 UTC
    I am tired of seeing Perl vs. PHP nodes. Haven't we discussed this to death already?

    Obviously PHP's popularity bothers certain monks. Deal with it.

    PHP is easier to learn and can be teached in high scholls.

    I am not a good speller, but your misspelling is too funny to ignore. And what's wrong with PHP being easier to learn than Perl? Many people think Ruby is easier to learn than Perl, but you don't hear Perl hackers complaining about it. Oh wait, Ruby is not as popular as PHP. What a bunch of whiners.

      Spelling corrected. Common... it was just a misprint...
        spellings fine, its the grammer

        ...and it can be taught in high schools...

        use brain;

      And who are you to bash others in for communicating? I'm tired of reading a thread that interests me then some douchebag jumps in to kill it with some highly opinionated bully talk and zero usable facts. No compassion, no value to add just white noise and ego. You are useless. use consciousness; Oh wait ... the package is incompatible with your system. I get it. By bad.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://382763]
Approved by itub
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-07-28 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (209 votes), past polls