Jeff Atwood says that it doesn't matter that PHP sucks. Well, he's right and he's wrong.
Let's analyze it.
PHP has a few things going for it.
Pro: Writing a simple program is simple and straightforward.
Con: None.
Bottom line: It's easy to start seeing results.
Pro: No need for other template languages.
Con: Strong temptation to mix display and logic code.
Bottom line: It's easy to start seeing results.
Pro: A big win for finding the code you're looking for.
Con: Makes for lots of spaghetti/duplicated code code.
Bottom line: When there's a problem with a page, you know where to look.
Pro: Lots of hosts to choose from---your code will run anywhere.
Con: None.
Bottom line: You can choose the host you want.
Pro: Bugs are worked out. Lots of documentation. Lots of libraries.
Con: None.
Bottom line: All of your questions are answered.
These things help you build a site fast.
PHP sucks for a number of reasons:
You can't do much more than procedural abstraction. OO in PHP is crude. Code size is directly proportional to software complexity.
Good luck doing anything complex.
The functions are horribly named. It's just one flat namespace.
Good luck guessing a function name.
Once your code gets complex, you have to start splitting your code into multiple files.
Good luck finding your code now.
What this all amounts to is this:
It's easy to write a simple site. It's hard to write a complex site.
Jeff gives some examples of huge, successful sites that use (or used) PHP. YouTube, Wikipedia, Digg, Wordpress, Facebook.
I'll address Wordpress last, because it's different. Wordpress is software you install on your own server. But the rest are basically just a few dynamically generated pages.
The other sites, I argue, are not very complex at all. Every time I use Facebook, I marvel at how simple it is. I always think to myself: wow, this is such a simple site. It feels like it's just a handful of PHP scripts. And it probably started that way.
YouTube is just a home page, some configuration pages, and the video pages. The real magic of the site is the flash video player. The rest just seems like commodity features you can find anywhere.
Wikipedia probably has the most complex software behind it. But it, too, doesn't do anything revolutionary.
I don't think I've ever used Digg, so I won't comment.
Wordpress is great software. I still use it. It's got some good features, but most features don't extend beyond one page. That is, each piece of user functionality requires a separate PHP file.
The real value in YouTube, Wikipedia, Facebook, and Digg are their marketshare. Their user base. They do a couple of simple things well. They do the right things well. And they have lots of users.
They are (arguably) revolutionary. But it wasn't because they are built on complex, ground breaking software. They changed the game because they do something simple that everybody wants.
Wordpress is easy to install on basically any web host. The install is butt-simple. That's its advantage. And it does all of the things everyone expects from a blog.
Jeff posits that "building a compelling application is far more important than choice of language". I have to agree. You should prioritize functionality over language choice.
But his second conclusion that "sufficiently talented coders can write great applications in terrible languages" is somewhat misleading. The examples he gives are great and are written in a terrible language. However, this does not mean that every great application can be written in PHP. Only some simple applications can be written in PHP.
So my conclusion: PHP sucks, but it doesn't matter for some applications. If you want to write a quick, one-off database-driven app, use PHP. If you want to do anything more complex than that, pick a different language.
Comments
"So my conclusion: PHP sucks"
Spoken like someone that doesn't know how to properly use PHP or a fanboy for another language.
PHP doesn't suck, crappy developers suck.
Touche'!
Yes, it does come off as a fanboy. And I suppose I must expect some name-calling after I tossed around the "suck" so much.
But note that all languages suck, at the moment. It is like saying "These wooden clubs suck!" before the sword is invented. It might sound weird, because you have nothing to compare it to (except hurling rocks). I'm just expressing how tired I am after bashing in people's skulls. I want a more efficient way to kill.
But name-calling aside, I was commenting more on the idea that you could say that programming language doesn't matter at all. That is what Jeff was implying on Coding Horror. He says it doesn't matter how bad a language is. He says it doesn't matter how many people think it's bad. And he shows some examples of good apps in a bad language. (Note: he calls it a bad language).
But what he's really doing (in our metaphor) is pointing at some bruised bodies and saying "Look, they're dead! It doesn't matter that the weapon sucks!" But bruised bodies are the forte of wooden clubs --- so of course you're going to get bruised bodies. Accordingly, he's pointing to database-driven apps, all using a "page model" -- the forte of PHP.
But I don't want to see bruised bodies. I want to see elegant cuts and well-placed stabs -- things you can't do with a club. Not easily, at least.
What languages do you recomend?
Can you give an example of a more complex application and the language you would use?
GMail
GMail is a good example. All written in Java and partly translated to Javascript. I would think that would be mighty hard with PHP.
Java != Javascript
Java != Javascript...it's not even remotely related. So "translated" is a big word.
GMail is also probably written in Python...
BTW, your article is not very rational.
I think he realises this. He
I think he realises this. He is referring to the fact that Gmail is partially written in GWT - which is a tool that lets you write Java code which is then compiled out into HTML and Javascript. It's quite possible that the backend is either Java or Python.
'Sucks' reasons misguided as usual
"OO in PHP is crude."
How so? It's got classes with subclassing and interfaces. It's got attributes, methods, static methods, static attributes, and constants. It's not terribly different from Java, C++, C#, or even Python. It's even pretty easy to add getters and setters and handle dynamic method call dispatch.
"Once your code gets complex, you have to start splitting your code into multiple files.
Good luck finding your code now."
All my projects (even in PHP4) are organized as one class per file. Just like how one would organize code in just about every other object oriented language. With PHP5's autoload functionality, my class names are mapped to files and loaded on demand. Why would you assume there would be any difference?
The only valid point you have is that PHP has a horrible library design. In some cases even that is defendable; PHP thinly wraps a lot of existing C libraries. Take the MySQL functions, if you want a high-level abstraction, you can provide it in PHP. Other languages that interface with MySQL are calling the same C libraries but you're just provided with (and locked into) one high-level abstraction. I do concede that some function naming (and parameter layout) is just messed up for no good reason.
I concede . . .
Thanks for your comment and your insights into the Object Oriented features of PHP. I truly was not aware of how full-featured PHP is in that area. Java-like OO is a step forward from procedural C.
To answer your question: I did not assume there would be any difference. I merely meant to point out that one of the advantages of PHP is lost when the code becomes big enough to warrant multiple files. An expert can look at a page and say "Oh, that's part of the header function", but someone else might not know where to look without first understanding the entirety of the page.
My point was not clear. I did not mean to argue that PHP sucks. I meant to point out what kinds of applications it doesn't suck for and why. Each language has a forte, a niche, a shtick. At the same time, each language has a domain to which it is not suited.
Thanks again for your patience.
OO in PHP is crude
The fact that you're taking a dynamic language and comparing its OO features to those of (mainly) static languages is somewhat telling. Things like closures and mixins are only possible by ugly hacks, and PHP polymorphism sucks (no late binding).
Compared to things liky Python and Ruby, or even Objective-C, I totally think PHP's crude.
My experience with PHP
One file per URL is something I've never seen in a professional PHP project. If nothing else, there is always a include to help keep look and feel consistent, and another to deal with the database connect.
PHP last I used it was in desperate need of better libraries.
Mixing logic and presentation is usually bad, but having function to create something like a textbox that validates an email address is REALLY useful, and helps keep code readable because the javascript is stored in libraries, and not mixed with other code.
The scary sites are the ones that just use index.php with a bunch of parameters. Scary scary spaghetti code that.
PHP needed to lock down on security long before they did. I know of a lot of legacy php that is exploitable, maybe even in an automated fashion.
PHP is a language that is easy to program in badly, but that's true of most languages.
PHP5 doesn't count
PHP5 certainly improves on some of those problems - the OO is better - but it doesn't count. Most webhosts still don't provide it, even as an option let alone as the default, so most users don't use it, so the advantages of the large user base don't apply. The problem is that the people behind PHP have so little grasp of the language development process that they alienated their user base by making incompatible breaking changes to important parts of the language in a minor point release of version 4, so that as a result everyone who had to rely on PHP for real work decided to avoid upgrading. I hear the upgrade from 4 to 5 is relatively simple, due to backward compatibility, but it's still not good enough.
So your point remains, because PHP means PHP4 for the foreseeable future.
I can't believe what you say
Facebook has caching/load-balancing code/live chat/etc.
Yeah, the chat system written
Yeah, the chat system written in erlang, and they produced an in-house RPC system that talks to python, java, ruby, php... I would guess that most of their non-UI code is not php.
Actually, Youtube doesn't use
Actually, Youtube doesn't use php much either. It used to but it recently (pre-Google) switched to Python.
Another article
about PHP.
http://mamchenkov.net/wordpress/2008/06/04/where-did-all-the-php-program...
Post new comment