Don't let the scaling police and architecture astronauts fool you: with the right architecture in place (i.e. a framework like Cake or Zend) and a smart scaling strategy (opcode caching, object caching, page caching, etc), PHP is a great choice for web applications.
Sure PHP has a low barrier to entry, which can lead to poor coding practices, but that shouldn't be a reason for people to express an absolute hate for it. Rather, it's important to stress continual education regardless of which programming language you choose.
Here are features I like to have (in no particular order):
* lexically-scoped variables (and closures)
* lambdas
* continuations
* macros
* an object system with a MOP (PHP and Java fail miserably here)
* powerful regex engine (can be added via libraries, so not too critical)
* extensive module library
* flexibility (I want to write code my way, not the way someone else thinks I should write it; bye bye, Python.)
Things that are nice to have: * multiple dispatch OO
* partial evaluation
* laziness
PHP has none of these features. That's why I don't use it and don't recommend it. And oh yeah... PHP is a templating system too. I would rather get that as a library, not a core feature. (But I won't count that against them.)So what language does have all these features? None :)
But, Lisp and Perl are good compromises. CL does everything except continuations and having a decent module library; Perl does everything except have pretty syntax and macros. Sadly neither of those languages has (by default) the "optional features", which is a shame. I ranted about this on my blog:
http://blog.jrock.us/articles/Syntax%20and%20features.pod
Anyway, PHP is junk in terms of a programming language. It's fine if you don't know how to program, don't know what abstraction is, and don't like using libraries.
But, I feel uncomfortable every time something I write takes two or three times the lines of code because of what the language lacks. First class functions or lambdas, closures, and a good library fall into this category...and PHP fails on all of them (there are many PHP libraries, but most are buggy and rather scary, and the standard library has ad hoc'ery written all over it...I like for the standard library to at least be a little bit planned out rather than crammed in via 3000 or so functions in the same name space).
But PHP is a perfectly valid language for many classes of problem. Just be careful not to use it for the classes of problems for which it is extremely poorly suited.
While I agree with your actual premise ; this statement is pretty bad form. It is the logical equivalent of a Christian saying that in order for me to critique his faith, I must become a Christian.
Replying, "you wouldn't know; you're an imperative programmer" is moot; maybe he is an imperative programmer - but he could also be correct. There is no connection between the two. Deductive logic has never been allowed in the scientific method, which is, ultimately, the barometer of truth.
I'm aware that Graham is the originator of this somewhat popular meme, but it's a wrong popular meme. The nature of ignorance of certain desirable features can only explain why people don't immediately demand them; it doesn't prove their usefulness.
That's obviously not what I said. My reply was, "If you believe all of the features listed above are useless in a real world development situation, I'm not capable of convincing you otherwise, as we're going to be speaking very different languages". I think there is a difference, though I can see how it comes off as arrogant. It wasn't really intended that way--I'm not a great programmer, and never claimed to be. But I know what makes me (as an adventurous, but not necessarily brilliant, hacker) more productive is good tools. And first class functions, closures, and a great set of libraries (like that found in Perl, Python, and to a lesser degree Ruby), are the tools save me lots of time. When I develop in PHP, and I do so pretty frequently, I miss all of those features constantly and my code is longer, less readable, and harder to maintain.
My point was if you haven't worked with a language that has those features you wouldn't be aware of how much time, and how many lines of code, they can save you. I'm not a smug lisp weenie pushing the blub paradigm (though there is definitely something to the argument) or implying that imperative developers are the scum of the earth. I'm a pragmatic sort of fellow...if it works, use it. But if something works better, why not use it instead?
That said, one of the places where PHP is a perfectly valid language is web applications. Some of the largest applications in the world run on PHP--Facebook, many Yahoo sites, etc. But they also have lots of languages doing the non-frontend work, because PHP is really horrible at a lot of backend tasks. Data and systems management, for example, where Perl and Python, or Java (depending on scale and performance requirements and existence of libraries), would be a better choice.
Good reply, looks like I made a mistake about part of your opinion, but I can't agree with you about not being the value of these features being difficult to explain. I always just explain situations where closures/anonymous functions work well (while I'm not much of a web programmer, I can think of a couple of examples). I agree, there is something to the blub concept. There certainly is a spectrum of languages.
It's only on a tactical level that you see "There is one way to do it" in action.
PHP is horrible because it is like an higher level of C, with an horrible standard library where the same thing can be done in 5 different ways, without literals for the most basic data types like arrays, without the simplest meta-programming abilities (assuming you don't want to use eval of course), OOP in theory (with an horrible OOP system for a dynamic language) but with all the base types that are not, and so on.
You know, I assumed that would bother me a lot more than it actually does.
So go write your program in Lisp, but don't complain when you discover how few developers out there are capable of maintaining such an application.
Is English, with its hundreds of rules and exceptions, the best spoken language to communicate in? Of course not. But it's ubiquitous, and that's all that matters.
Though I haven't met him in real life, I'm quite familiar with jrockway's work and he's hardly an "architecture astronaut" or in academia. He's a good programmer who gets real world work done. And guess what? I find his code well-written and easy to maintain. Go figure ...
Just because you don't need the items on his list, don't going throwing stones at those of us who do. You'd be like the people who rush out competitors to Microsoft Word on the theory that people only use 10% of the features -- only to discover everyone's using a different 10%.
I'd rather use a moderately crappy language in a decent development environment than a wonderful language that was lacking tools support. It's not all about the language.
With that said. I work on a PHP site that does 5-9 million page views a day. We have an in house MVC framework. We use MySQL, memcached and APC hosted on a handful of solaris zones. We have no issues scaling and have coding policies that our development team tries its best to follow. PHP is a proven language, it has been around a long time and has a huge community. It really comes down to preference and objective. I personally don't use any of the open source frameworks available. But there are plenty of decent ones that will work just fine for small to medium sized sites.
To anyone who says thats it's not a "real" language: do I care? It gets the same job done, it's proven to scale and it can turn a profit. Period.
But I use it for anything web-based because it gives me guaranteed results, anytime, anywhere, on whatever scale on whatever budget. I just wouldn't use it for sites with complex business logic, but let's face it, most websites, even the big ones, are hardly rocket-science in that respect.
What I love most is the dynamic of the PHP community. For instance, when RoR arrived on the scene, the response wasn't to dis RoR or run scared, but more like "that's so cool, let's see if we can bring PHP to that level". And there is more sharing of knowledge and experience (and code) going on inside the PHP-community then any other developer community I know.
More then any development platform I know, PHP is alive and constantly developing, but still as easy to deploy and easy to learn as ever.
There's somebody I'd like you to meet: http://perlmonks.org
I've used PHP for a while -- a few years -- and haven't developed a particular loathing for it. That's saying something, since I'm disgusted by most of the tools I'm forced to use.
It's certainly capable enough and isn't hard to use. It's also more ubiquitous, and therefore arguably more portable, than Ruby or Python, although dealing with differences between PHP versions is a pretty royal pain.
Pretty much any reasonably skilled programmer can do a job in PHP without too much trouble. You'll get more cred for using Python or Ruby though.
Here are the average salaries for permanent jobs over the last 3 months according to http://itjobwatch.co.uk:
Python: £45,282
Django: £42,326
RoR: £41,204
Ruby: £39,897
PHP: £33,004
Number of salaries quoted for the past 3 months: PHP: 5283
RoR: 454
Django: 46
Thanks for pointing that out.
Perl: £44,300 (£45,500 if you count "CPAN" as Perl)
Since most medium-small sites have an irrepressible tendency to grow into medium and even large sites, I'd stay away from PHP for anything other than a quick and simple site.
Ruby and Python are much more sustainable in the medium term and even the long term, and just as quick to throw applications together. Sure, they won't last forever, and eventually you may have to rewrite critical bits in another language, but in the meantime it works to release something quickly and keep improving it for a few years.
Daniel
As a language for scaling... not too shabby. Many people who bash PHP for inability to scale really don't know jack shit about what they're talking about. Chances are, their app is slow because of all the O(n^2) loops... and they need to go take a class or two on algorithms, networking, and/or distributed systems.
I used to work with PHP a lot... eventually moved to Python simply because it was more succinct. Our teams are extremely small, and we needed a more expressive language; needed to get more done in less time. The rest speaks for itself...
We actually have moved from 100% PHP to: python for web apps, decent amount of Io & Ruby for utilities/monitoring and such, and working on a load balancer in Erlang... much more powerful development. And we really haven't run into many major stability problems...
Daniel
They also remarked that they are looking into using Symfony framework in their software.
Facebook and Digg are two other notable mention of php usage. Both are handling very high traffic loads ok (not spectacular), and I know that facebook is using a lot of C/C++ and some Java on the backend. The main reason that they are php is b/c it was the better choice for the founders, to do something quick at the time (2004-2005).
Ruby on Rails was not even out, and Python didn't have great and simple frameworks with simple learning curve.
So, at the time the two sensible choices were Java or. Php. A great question would be: If facebook or digg had to redo everything from the beginning, would have still chosen php?
Why compare Y!'s stock performance to their underlying technology? Makes no sense.
which is just enough rope to hang yourself with.
To be honest, part of it will depend on your style and part of it will depend on your discipline.
I'm a fan of Python. PHP is not my style. I like one way of doing things. I like namespaces. I don't like all the extra syntax that I feel is useless ({};$).
But that's just me personally. Many people hate python for those reasons - it's constraining.
Objectively, PHP allows you to do what you want easily. The only problem is that taking those shortcuts can come back to bite you later. If you appropriately use include(), make sure to template out design, and avoid some of those oh-so-irresistible hacky things, you'll be fine. Digg has done well with PHP.
The problem is that it's hard to know exactly where you're screwing up sometimes. For example, in python, every name used in a python source was defined either in that file or in one of the imports. That makes it trivial to figure out why that "I can't find that name" error is occurring. With PHP, that name could be meant to be included 10 files back. They simply all carry over.
So, is PHP bad? I personally think it is, but I'm a little conservative an authoritarian when it comes to programming rather than PHP's more loose style. Can PHP's style help you? Yes.
For the good of your soul, use a framework. We currently like Zend Framework, but I've heard good things about CakePHP and Symfony. If you stick with the framework and follow a sane MVC strategy you'll fix most of the problems you'll have using PHP as an HTML templating language.
benchmarks: http://tinyurl.com/5dcjzd
We develop our own framework.
To be honest, it doesn't feel much like PHP on the average bit of coding. It feels like a "real" language most of the time because of the framework. They have one of the best user guides I've ever run into (click Table of Contents at top): http://codeigniter.com/user_guide/
Granted there are times that its inconsistent library and lack of language features can become annoying. If we're discussing languages alone, PHP is certainly lacking.
With projects like mod_rails on the horizon and programmers trending away from PHP hopefully we soon won't need to choose between a solid language and super-simple deployment process.
i think php is a great low memory solution, when you get into higher memory loads for the app to process, you do not want to reload everything back in to ram for each request. php is single threaded per request, and as such you don't have access to sockets, or other event based activities on the server side.
i agree with the statement in general, that you should go with what you know to be the most efficient language for the task.
It's not terrible, but I've found that the clunky syntax for slightly more advanced stuff (e.g. anonymous blocks) really discourages some labor-saving and repetition-avoiding coding practices that a language like Ruby encourages.
It's a really good fit for small-scale sites with well-defined requirements. But it requires some well-thought-out conventions to scale well, the sort of stuff you can't come up with unless you've done it wrong a couple of times yourself. Unless you borrow someone else's work by using one of the frameworks out there.
But then of course we should all take a step back and realize that Facebook is built on PHP, haha.
Scaling isn't even a real, real problem you need to worry about until you're a top 1000 site at minimum, or > 10MM page views a day. At numbers past that, no framework is going to magically solve your database partitioning problems.
Mind you, when you're getting into the more functional side of Ruby or Python, PHP starts to show its limits as a language. But it's still fast to code in and to do so well if you know what you're doing.
PHP's standard library is not object oriented
75 array functions
47 of them start with array_
28 do not
Out of the 28 that do not, you have such greats as: usort, sort, rsort, asort, arsort, krsort, uksort, uasort
Nuf said.
On that note, I am tired of articles comparing PHP to Rails. It's like comparing a Honda to the metal used to build another car.
I'm using Ruby now and I would never go back.
Here's my rough order of language preference for server-side languages that I have experience in: Ruby > Python > C# > PHP > Perl > Visual Basic > Java > C
My point about using a framework wasn't to knock PHP; it was more a piece of advice - "if you do use it, you'll need to be aware of this".
However, I recently read an article on YC about how many startups go through a phase debating about which language an application should be built on. We did not give this much thought as we saw a few prominent websites like facebook use PHP and we thought PHP seemed to be a pretty scalable language. Plus, with support for OOP (as of PHP 5), PHP seemed to be a pretty good choice.
I am interested in evaluating if we made the right decision
However, I never want to use it again myself. I'm tired of digging through horrible code written by people without a clue.
Here are a few Python language features that I seriously miss when I'm working in PHP:
- Modules and namespaces! This is the feature that initially drove me away from PHP.
- List comprehensions (let you construct a new list based on an old list in a one-liner)
- Built in iterator support (easy "for item in collection" support for many different types of collection)
- First class functions and closures (so you can treat your functions as data)
Those are just four off the top of my head. If you haven't looked at Python before (but already know how to program) I suggest taking a look at http://diveintopython.org/ which is a free online book.
Namespace support in PHP never really bothered me, but I've occasionally run into problems with name clashes with built in functions. It'll be welcomed anyway for sure.
Python is a very good language: easy to learn, powerful and fast enough (provided you understand how to make its various frameworks scale).
Our app is nearly entirely client side, with a little server side PHP glue. Something like Rails would be overkill.
Myself, I'm just now getting started into Ruby on Rails. I finally figured out a project to get me interested in learning the Rails part of it. I just need to get cracking.
I just do not like to code in the language.
/me ducks