Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Is Perl a good career move?

by Juerd (Abbot)
on Jan 13, 2005 at 20:31 UTC ( #422100=note: print w/ replies, xml ) Need Help??


in reply to Re: Is Perl a good career move?
in thread Is Perl a good career move?

I'll point out that moving from Perl to PHP is *very* easy.

Is it really? Perhaps you are right for simple web based stuff like a mail form, a simple database driven site or just templating. However, real programming isn't translated to PHP so easily.

First of all, what are you going to do with namespaces? PHP still does not have namespaces.

Then, what will you do with closures? PHP has no closures. Heck, it doesn't even have anonymous functions. That's another thing: how will you be rewriting that hash of coderefs? A hash of strings that are evaled at runtime?

And what about all those objects that aren't simple hashes?

But let's assume you didn't use any of these slightly more advanced programming techniques than the average PHP "programmer" can handle. But you did use modules. You do use modules, don't you?

PHP is a web programming language, so it must have a good HTML parser ready, right? One is available, but it cannot be called good. It cannot even parse processing instructions like, ehm, <?php ...?> itself.

Another common task in web programming is sending HTML mail with a few inline images. So what alternative for MIME::Lite do you have? The PHP-ish solution is to build the message manually. Good luck, and have fun.

But at least it can open files over HTTP. Yes, that it can. But what do you do if you want more than that? What if you want to provide POST content, headers, or implement ETags? Then, you must use Curl, which isn't nearly as convenient as LWP. Don't even think about having something like WWW::Mechanize in PHP.

Enough with the modules. I think I've proven my point that CPAN makes Perl strong. Now let's discuss the core. In fact, let's focus on something extremely elementary in programming: arrays!

PHP's "arrays" are hashes. It does not have arrays in the sense that most languages have them. You can't just translate $foo[4] = 4; $foo[2] = 2; foreach $element (@foo) { print $element } to $foo[4] = 4; $foo[2] = 2; foreach ($foo as $element) { print $element }. The Perl version prints 24, PHP insists on 42. Yes, there is ksort(), but that isn't something you can guess. It requires very in-depth knowledge of PHP. And that's the one thing PHP's documentation tries to avoid :)

Also, don't think $foo = bar() || $baz does the same in PHP. In PHP, you end up with true or false. So you must write it in two separate expressions.

Exactly what makes you think and even say moving from Perl to PHP is easy? It's very, very hard to un-learn concise programming and go back to medieval programming times. And converting existing code is even harder.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


Comment on Re^2: Is Perl a good career move?
Select or Download Code
Re^3: Is Perl a good career move?
by TrekNoid (Pilgrim) on Jan 13, 2005 at 22:45 UTC
    Exactly what makes you think and even say moving from Perl to PHP is easy? It's very, very hard to un-learn concise programming and go back to medieval programming times. And converting existing code is even harder.

    I wasn't speaking in the context of 'leave Perl behind and go to PHP'... I was speaking in the context the original poster was asking...

    Unlike a lot of folks here, I'm not a person that works with Perl every day... I don't write a *lot* of Perl a year... I write enough that I consider it my favorite language now, but I'm nowhere near Saint-worthy... As a result, my understanding of a lot of the things you mention is limited... and my basis for comparison of the two is viewed through the eyes of someone who isn't an expert in either language, but who found the syntax of the two so similar that he was able to do some PHP work after only a few hours, mostly because I had been working in Perl for 3 years.

    I know I said I'd been writing code for 19+ years, and that's true... The first 12 years of that were BBX (Business Basic Extended) and COBOL... PL/SQL for the last 7, and Perl during the last three... Should, I hope, explain my scope of understanding better.

    I'm not suggesting, in any way, that it's comparable in scope or maturity, because it isn't... I'm just asserting that it isn't that hard to pick up and work with, ie... countermanding the OP's speculation that somehow Java prepared you better to learn other languages, and Perl didn't.

    But I'll gladly concede your points to someone with more knowledge on the differences in the two languages...

    TrekNoid

Re^3: Is Perl a good career move?
by Anonymous Monk on Feb 02, 2005 at 02:19 UTC

    Your post has helped me so much. I'm a pretty slow learner so don't go along with the idea of learning serveral languages - especially when one of them - PHP - is a bastardised, inferior version of something I spent years learning - Perl. So many programmers use throw away comparisons betwen PHP and Perl as if their syntax is virtually the same but I've had terrible trouble having to use PHP for some web projects coming from a Perl background. PHP syntax makes me wince, compared with the elegance of Perl. Unlike you multi-linguistic programmers I HAVE to specialise in 1 server-side scripting language to get anywhere with it. I believe in sharpening a single tool rather than trying to be a master of all trades. Perl, with CPAN, is enough to occupy a lifetime anyway so I don't understand where all you multi-linguists find the time to be excellent in so many languages. Competent, maybe, but excellent, no.

    I've reached the point where I'm considering leaving all PHP work well alone because it's having a detrimental effect on my Perl skills. It just encourages so many bad habits.

Re^3: Is Perl a good career move?
by soup (Initiate) on Feb 21, 2005 at 14:27 UTC
    I think learning PHP as a PERL developer is very easy, but the other way around might be a little more daunting. My question is why should you want to switch from PERL to PHP. This is like saying that people who speak German should switch to English, just because it's easier to learn. As far as I'm concerned you are better of speaking German in Germany. What I'm trying to say is that sometimes programs need to be written in PERL and other times in PHP or ASP for that matter. Do not switch but increase your knowledge, it's always handy to know how to speak different languages. As for all the built-in PHP functions, it's enough to know that it's possible, you don't have to remember each one of these functions! I've been programming with PHP since version 3 and still sometimes I have to look up (thanks to inconsistent function names(I'll give you that)) in which order the function requires its parameters.

    Furthermore I'd like to point out that PERL and PHP are by no means interchangeable, so learn both. In practice you cannot build all your applications in your favourite scripting language, simply because different customers use different platforms and environments. Planning a career move in just one scripting language limits you to a handful of jobs. In the end you'll see that scripting languages differ very little from each other. Some are better equipped to do some chores, while others are better at other stuff. In the end they all work in more or less the same way.

    Let me point out that I love PERL and that I've also got a weakness for PHP, but this is basically because I'm an Open Source disciple. Let's not worry too much about the differences. It's possible to use both you know!

      It's not PERL. Perl is not an acronym.

      Re natural languages: there are things I can express in Esperanto, but not in Dutch. There are things I can express in Dutch, but not in English. I know these three languages fairly well. Funnily, it's exactly the other way around here: the easiest to learn language is also the most expressive one.

      It is possible to use both Perl and PHP, but it is not easy. Once your mind thinks in maps, greps, arrays, lexicals, closures, namespaces and short circuiting operators, PHP is a major pain in the ass. You can still get the job done, but it hurts mentally and IMO, not much is worth that. (Note: do not read that as "that is not worth much")

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        Doesn't Perl stand for Practical Extraction and Reporting Language? I could very easily be wrong though! Anyway, I will refrain from using PERL in future, to avoid straying from the subject.

        In my honest opinion Perl is a great language to learn how to program and by no means least, how to be creative. Someone else in this thread mentioned something along the lines of if you know Perl, you know how to tackle problems. Creativity and knowing how to tackle problems are essential skills required for handling real-life problematic situations, no matter what language you use. So in that respect Perl is a great career move. If another language has shortcomings, find a way around it or better still, use a language more suitable for the job. That is, if you are free to choose, ofcourse!

        Once your mind thinks in maps, greps, arrays, lexicals, closures, namespaces and short circuiting operators, PHP is a major pain in the ass.

        Actually, most languages become a major pain in the ass at that point. :-)

        And it makes me understand quite well what makes LISP hackers so grumpy about many other languages. After all,

        We all recall that Perl est un esprit LISP dans un corps C, n'est-ce pas? :-) (“corps C” sounds like “corset” in French.)
        —Philippe Verdret

        Makeshifts last the longest.

Re^3: Is Perl a good career move?
by thinker (Parson) on May 24, 2005 at 12:50 UTC

    Hi Juerd,

    You make some excellent points about PHP, (and having spent much of the last 2 years as a PHP programmer, I agree with many of your points). In particular the namespace issue is a killer (although using OO techniques you can avoid the problem to a degree). You have also made some errors in your comments.

    >>> Heck, it doesn't even have anonymous functions.

    Yes it does.

    >>> That's another thing: how will you be rewriting that hash of coderefs? A hash of strings that are evaled at runtime?

    #!/usr/bin/php -q <?php error_reporting(E_ALL); $dispatch_table = array( # create some anonymous functions 'foo' => create_function('$a', 'return "foo got $a\n";'), 'bar' => create_function('$a', 'return "bar got $a\n";'), 'baz' => create_function('$a', 'return "baz got $a\n";') ); print $dispatch_table['foo']('hello'); print $dispatch_table['bar']('hi'); print $dispatch_table['baz']('yo'); ?> # outputs foo got hello bar got hi baz got yo

    >>> Also, don't think $foo = bar() || $baz does the same in PHP. In PHP, you end up with true or false. So you must write it in two separate expressions.

    $baz = "DEFAULT VALUE"; function bar(){return "Assigned value";} function quux(){return false;} $foo = bar() ? bar() : $baz; print "$foo\n"; $foo = quux() ? quux : $baz; print "$foo\n"; # outputs Assigned value DEFAULT VALUE

    I'm not sure if you could consider that as two separate expressions, but it seems a concise enough idiom for me.

    While PHP does not have closures, I have used static variables in functions to emulate some of the behaviours I have used closures for in Perl.

    Perl remains, by far, my language of choice, but I thought it would only be fair to point these things out

    cheers

    thinker

      Heck, it doesn't even have anonymous functions.
      Yes it does. (...) create_function.

      Functions created by create_functions are NAMED, not anonymous. In fact, create_function RETURNS the name.

      I'm not sure if you could consider that as two separate expressions, but it seems a concise enough idiom for me.

      I sure do. If in "bar() ? bar() : $foo", the bar function does something impure, like increase a counter, it does so twice, while with Perl's "bar() || $foo", it is done only once. Also, if bar() takes 10 seconds to finish, then "bar() ? bar() : $foo" will take at least 20.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        >> Functions created by create_functions are NAMED, not anonymous. In fact, create_function RETURNS the name.

        Create function does indeed return a string, but does that mean it is not an anonymous function. perhaps we are concentrating too much on semantics here

        The documentation for the function states " create_function -- Create an anonymous (lambda-style) function". Perhaps more semantics. Nevertheless, building a dispatch table from the result of create_function works for me.

        I take on board your point about ||= for a function which has side effects

        cheers

        thinker

        ($foo = bar()) || ($foo = $baz); $foo = (($bar = bar()) ? $bar : $baz); The key is that the || casts the right hand side as a boolean, and php does not have a magic variable that gets set while you aren't looking.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2014-10-23 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls