I actually see the PHP bashing as dieing down quite a bit, Now that the Ruby on Rails craze is over with (the language is awesome, but I'm glad to see some of the hype go away).
I think people are finally understanding that there is room for both languages (and more) and each language has it's strengths and weaknesses than can only be leveraged (or overcome) by someone truly comfortable with that language.
Yeah, I don't really understand this. My first language was C, and all these C-like languages look quite similar in syntax. I never thought these were "pretty," but they don't really stroke an emotional component in me.
My point is that PHP's lack of namespace hierarchy is just like C. In fact, most of PHP's libraries are very close to the underlying C libraries. The lack of apparent organization is mainly due to the fact that PHP pulls all these different, independently-written libraries together. If you were writing C, it would look about the same, except that you'd have to go out and find all these libraries and put them together yourself.
I have used both for different purposes and I can honestly say conceptually C is a very clean, fast assembly language substitute. If some dumb programmer pulls together 20 C libraries with different semantics and does not properly abstract over them and unify things it's the programmer that's the problem. PHP is fundamentally messy because of just that reason PLUS other significant problems at the language, not library level.
PHP is pragmatic and pretty fast, but everything, everything, everything, beyond the "HTML template language" bits, are bolted on with whatever tools were handy at the moment. I'd be stunned if more than a couple hours of design work went into the object system, the type system (where == and === are used for evil rather than good), or even the standard library function names.
It has some strengths: Big library (not as big or as high quality as CPAN, so if library support is what you need, go for Perl), a lot of example code (but it's mostly horrible quality...even good examples are pretty bad in spots), and really easy deployment. So, if you're building an Open Source project that you want a lot of people to use, it's a great choice--PHP is available on every hosting server on the planet. Or, if you need a "blank-plus-this-widget" you can probably find the "blank" already written in PHP and then build your "widget" on top.
But, if you're starting from scratch, why commit yourself to working with a shoddy language for the months or years it'll take to finish? There are good imperative languages out there for web app development: Ruby and Python, in particular. Though the frameworks craze for these languages are partly to bridge the gap that they have with PHP (they're all missing a "view" layer for the web, because PHP is a reasonably powerful, if ugly, template system), and a lot of the other crap just makes things ugly...they get built for one particular application and then stretched for general-purpose use, and in the stretching they get a bit misshapen and hard to fit into any specific task.
Anyway, Ruby and Python are pretty and reasonably consistent languages that are nice to work with. PHP is neither. Perl...well, it ain't necessarily pretty, but CPAN is hard to beat when you just want to get the job done...and you can treat it as a functional language pretty effectively, which is all the rage around these parts (and you'll probably want to after you see the bolted on object system).
Well, mostly just that PHP has been extended far beyond the simple templating language it was designed as.
My language of choice (ruby or haskell, take your pick) was designed for more general tasks, and so is simpler to write the more general web apps people are building now. I would still like to use PHP as my template language, though.
PHP is still very fast when it comes to templating, but it's not very fast at all when doing any sort of number crunching. Ruby suffers here, too, which is why I'm trying to use haskell for my current project.
I often find myself defending PHP. It seems to be very unpopular lately, at least by some very vocal individuals on the web. I like PHP, and here's why:
It runs everywhere, has lots of libraries, and most of my friends know it.
That, for me, is huge. It's enough for me to forgive, tolerate, and even enjoy programming in the language.
Anyway, here's what I don't like:
The lack of a decent module system.
The lack of closures.
The weird reference semantics of objects in PHP4. PHP5 is way better in this regard, but now I have to worry about whether my code will still run on PHP4, and whether or not I will need it to.
The clumsy templating syntax. Short tags help, but I'm supposed to feel guilty if I use them.
The need to use unreliable third-party software to get bytecode precompilation, causing me to worry about the performance costs of modularity. (!)
Magic quotes. And the fact that I may need to undo them depending on the whims of system administrators.
Arrays. I wish dictionaries and lists were separate concepts like they are in Python and many other languages I want to interoperate with.
The name. I hate when I have to explain what PHP stands for. I feel like enough of a geek as it is.
Really, I could go on a rant about speed and security, but it's just ugly. I do most of my coding in Python now days which spoils me. I look at php and it's a nasty mashup of code, data, and structure all rubbed into one nasty little steaming pile. Python is pretty and that's why I like it. It's easy to read, easy to understand, and does not explode into a visual cacophony like I've seen most php projects do.
I'd use php for a small simple one off thing because it is stupidly simple to get a page working with no fuss. I also have no issue using php products like Wordpress or PHPBB. My first web startup I wrote in php and it was a pain to maintain after a while. Anything large I'll stay away.
Have you checked out Code Igniter? It is a php framework that implements the MVC design pattern. Forcing the seperation of the different layers makes things much "prettier" in my opinion.
"You can nest function declarations, but with limited effect. Nested declarations do not limit the visibility of the inner-defined function, which may be called from anywhere in your program. The inner function does not automatically get the outer function's arguments. And, finally, the inner function cannot be called until the outer function has been called."
That's from "Programming PHP" by Rasmus Lerdorf et al.
This sort of messiness, repeated dozens of times in various ways is why I try my best to avoid PHP.
20 comments
[ 3.3 ms ] story [ 59.8 ms ] threadI think people are finally understanding that there is room for both languages (and more) and each language has it's strengths and weaknesses than can only be leveraged (or overcome) by someone truly comfortable with that language.
I didn't get that memo.
It's a nightmare. How about some organization? How about a hierarchy? How about some terseness?
It has some strengths: Big library (not as big or as high quality as CPAN, so if library support is what you need, go for Perl), a lot of example code (but it's mostly horrible quality...even good examples are pretty bad in spots), and really easy deployment. So, if you're building an Open Source project that you want a lot of people to use, it's a great choice--PHP is available on every hosting server on the planet. Or, if you need a "blank-plus-this-widget" you can probably find the "blank" already written in PHP and then build your "widget" on top.
But, if you're starting from scratch, why commit yourself to working with a shoddy language for the months or years it'll take to finish? There are good imperative languages out there for web app development: Ruby and Python, in particular. Though the frameworks craze for these languages are partly to bridge the gap that they have with PHP (they're all missing a "view" layer for the web, because PHP is a reasonably powerful, if ugly, template system), and a lot of the other crap just makes things ugly...they get built for one particular application and then stretched for general-purpose use, and in the stretching they get a bit misshapen and hard to fit into any specific task.
Anyway, Ruby and Python are pretty and reasonably consistent languages that are nice to work with. PHP is neither. Perl...well, it ain't necessarily pretty, but CPAN is hard to beat when you just want to get the job done...and you can treat it as a functional language pretty effectively, which is all the rage around these parts (and you'll probably want to after you see the bolted on object system).
My language of choice (ruby or haskell, take your pick) was designed for more general tasks, and so is simpler to write the more general web apps people are building now. I would still like to use PHP as my template language, though.
PHP is still very fast when it comes to templating, but it's not very fast at all when doing any sort of number crunching. Ruby suffers here, too, which is why I'm trying to use haskell for my current project.
It runs everywhere, has lots of libraries, and most of my friends know it.
That, for me, is huge. It's enough for me to forgive, tolerate, and even enjoy programming in the language.
Anyway, here's what I don't like:
The lack of a decent module system.
The lack of closures.
The weird reference semantics of objects in PHP4. PHP5 is way better in this regard, but now I have to worry about whether my code will still run on PHP4, and whether or not I will need it to.
The clumsy templating syntax. Short tags help, but I'm supposed to feel guilty if I use them.
The need to use unreliable third-party software to get bytecode precompilation, causing me to worry about the performance costs of modularity. (!)
Magic quotes. And the fact that I may need to undo them depending on the whims of system administrators.
Arrays. I wish dictionaries and lists were separate concepts like they are in Python and many other languages I want to interoperate with.
The name. I hate when I have to explain what PHP stands for. I feel like enough of a geek as it is.
http://www.google.com/search?q=why+php+sucks
A good resource for comparing languages is the shootout:
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all
Most people just refer to the overall scores, but what's more interesting is seeing the same program done in different languages.
This one is pretty straightforward:
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=php&id=0
Compare to the same thing in Python, Ruby, Scheme, Common Lisp, and Haskell:
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=python&id=0
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=ruby
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=chicken&id=3
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=sbcl
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=nbody&lang=ghc
Really, I could go on a rant about speed and security, but it's just ugly. I do most of my coding in Python now days which spoils me. I look at php and it's a nasty mashup of code, data, and structure all rubbed into one nasty little steaming pile. Python is pretty and that's why I like it. It's easy to read, easy to understand, and does not explode into a visual cacophony like I've seen most php projects do.
I'd use php for a small simple one off thing because it is stupidly simple to get a page working with no fuss. I also have no issue using php products like Wordpress or PHPBB. My first web startup I wrote in php and it was a pain to maintain after a while. Anything large I'll stay away.
Just because it's ugly and I have to stare at it.
http://www.codeigniter.com/
That's from "Programming PHP" by Rasmus Lerdorf et al.
This sort of messiness, repeated dozens of times in various ways is why I try my best to avoid PHP.
That did me in. Really.
http://brl.codesimply.net/