Why do I prefer PHP over Perl

30.01.2007, by Oles Hnatkevych, don_oles@able.com.ua

Both these two scripting programming languages belong to the same "class". In contrast to this article http://tnx.nl/php having some experience programming both Perl and PHP, I found using PHP much productive and easier. And here is why. Of course the problems I describe can be solved easily in Perl with just more deep documentation studying and are not problems at all, but the Perl man pages are still an unreadable mess for me.

All comes down to the problems that belong the essence of writing (typing) programs.

I prefer writing global instead of local and my

The regular program is just a big set of functions that programmers write. Each time I feel that I need a separate function in PHP I just write a function. I do not care about creating local variables here and there that will spoil my global namespace. If I have to use some global variable I use either $_GLOBALS["foo"] or global $foo. In Perl I have to use local or my here and there. Most functions I write use much more local variables than global, and my brain is more concentrated on a problem and not on declarations.

Arrays and complex data structures

As a programmer I find PHP arrays much easier than Perl two types of arrays, hash and index arrays. In PHP I can easily merge arrays of "different types", debug them with var_dump, "walking" nested arrays with simple recursive functions. Complex data structures become a real pain in Perl. Compare $a["b"]["c"] and $a->{"b"}->{"c"}. Yes!!! In PHP $a is actually a reference! No more stupid "dereferencing" mess. Of course you have to read manual to know the nuances.

Return value depends on context

I think that in Perl having function return different values depending on the context it is called, like "localtime", is ill-considered.

do vs include

If in Perl I "do" some another perl script(s), and it contains an error, Perl interpreter won't show me what script and line number in the script contains the error. I need to hack $SIG{__WARN__} etc. There's no such problem in PHP. I even can find how my functions called each other to get to this place.

"eq" vs "=="

When comes down what language is closer to the unix, it's really Perl. "= =" and "= = =" are more obvious for even a non-programmer than "eq", "gt" and other random character combinations. Perl inclination to use short abbreviations is it's weakness. Perl was designed to be a replacement for sh/awk/sed, and still it is:

Function names

Sometimes the flame about PHP function names "inconsistency" makes me feel that armaggedon is coming. But looking at perl's functions I get a feeling that the Cthulhu is going to wake soon: grep, lc, q, qq, tr, y, m, s, qr, qw, my, our, qx, uc. Please don't try to spell it! Don't disturb the beast. Fhtagn! Did the guys ever see anything else beyond unix shell?

CPAN

It makes me wonder why things like CPAN are considered to be advantage? Even when your perl script starts under mod_perl, you still have to use lot's of CPAN modules, and it really means much unnecessary code interpretation over and over again. Contrary, in PHP, most things are already compiled into extension modules written in pure C. That's much faster, believe me.

Speed

On my 800 MHz Celeron:
root# time perl -e 'for($i=0;$i<10000000;$i++){$a=$a+1;}'

real    0m16.066s
user    0m15.562s
sys     0m0.017s
root# time  php -r 'for($i=0;$i<10000000;$i++){$a=$a+1;}'

real    0m7.942s
user    0m6.703s
sys     0m0.086s
Surprise.

Truth through dark clouds

I know there are things that I am wrong about and not experienced enough. But the point is much simpler and wider.

After looking around and trashing out aberrations of perception the core feeling remains. And it tells me that the language indeed was not designed for people, it was not designed "to be simple" and "fast to learn" and "easy to use". It's credo is "There's more than one way to do it"! It's pronounced 'Tim Today'. Others are "Perl: the Swiss Army Chainsaw of Programming Languages" and "No unnecessary limits". That's it! No limits for perversion. It was designed just to show that it can be designed 'cool'. Actually it was not designed at all.

Tie our grep. Do chop map. Tell tr uc. Bless my sin.