I consider myself a programming polyglot. I am proficient in five to seven languages and am competent in many more. Consequently, like many programming polyglots, I am a bit of a snob. PHP programmers tend to be unilingual or bilingual (Javascript). They are unenlightened. If you asked the average PHP programmer to explain a closure, they would probably express bewilderment. Brutes! Like I said, I am a bit of a snob (and the preceding text was satirical…mostly).
As is the case with much snobbery, this is ill-advised. Prior to PHP, I remember writing applications through CGI, mod_perl, or full-blow C extensions to Apache httpd. It was not very productive. Enter, PHP. From the beginning, PHP was designed as a template language to make web development easy. As such, additions to the language and its tool set were evaluated against a fitness function that emphasized ease of use and productivity for web development. At the time, it was the strongest solution to a problem of increasing prevalence.
Fast forward a few years. I had been out of the web development scene completely when a bout of temporary insanity inspired me to attempt building an online dating site (thanks, Markus Frind). Since I used Ruby extensively for non-webdev, Rails was my obvious framework choice.
Does Rails have advantages that cannot be replicated in PHP? Of course! The most glaring advantage of Rails over PHP is the fact that PHP is not Ruby. Ruby is lovely language. Seriously. Ruby allows you to think in code. It is incredibly productive. You can take very complex abstractions and implement them in Ruby with ease. However, web development is not very complex. Most web development is CRUD. Sure, Ruby might be slow (although 1.9 is looking nice) but most applications really do not require high performance. And when scalability does become an issue, Rails is rarely the bottleneck.
Do I miss ruby gems? Sure, but Pear works. Moreover, integration with PHP is often easier than it is with rails. When was the last time you noticed that popular api or library lacked a PHP interface? Most sites release official PHP libraries (s3, ec2, facebook, gdata, …)
Conversely, PHP has one several advantages over Rails. Most notably, immediacy. Deployment via SCP is very satisfying. Moreover, PHP now has many rapid-development frameworks that employ MVC and active record patterns (e.g. CakePHP). While you don’t have the elegant sexiness of Ruby, you have almost everything else.
Do PHP programmers tend to be weak programmers who produce mediocre code? Maybe. If so, it can probably be attributed to the law of large numbers. There is a virtual army of PHP programmers; there are very few DHHs. For large-scale, very complex problems it may be better to use a language that naturally excludes poor to mediocre programmers, but this is not true for web development. Besides, there is no shortage of criticisms of the rails community.
Finally, there is nothing to stop you from using PHP for the CRUD front-end and Ruby or some other language to do more complex heavy lifting (e.g. spidering, categorization, etc). It seems to have worked well for facebook.
echo "Hello, Old Friend";
UPDATE(OCT-27-2009 @ 1:39)
END_UPDATE
This post was motivated by an open-source project I am currently coding. It is not yet released but for the purposes of this footnote, pretend it will have a deployment pattern similar to Wordpress. I started writing it in Rails. However, after speaking with several people who will be end-users, I realized that the most important factor would be ease of deployment. While Phusion is a game-changer for deploying Rails applications, I think PHP is still easier for most web developers.
Also, for the sake of disclosure, I should make it clear that I am not an expert web developer. As you might notice from this blog, most of my work is in complex systems. Most of my time is spent writing code in C or C++ with Ruby acting as glue.
Have you tried any of the ASP.NET languages? You might like C#
I have used C# and mono. C# has a steeper library learning curve and I have no need for it outside of web development. PHP’s learning curve is shallow. I thought ASP.net was particularly clunky, but that was a while ago. For now, I will be satisfied with PHP.
@John or anyone else who thinks ASP.NET is clunky (and rightly so, IMHO), you might consider giving the ASP.NET MVC Framework a shot — it removes all that clunkiness.
I agree completely.
Anyone who says they like Ruby over this, or that over PHP, or even PHP over something else is simply defining their preference.
New versions of PHP continue to keep it relevant.
There are numerous ways to either mimic the functionality of closures in PHP, or get something close enough that is built in to easily circumvent the deployment cycle and availability issues of things like Ruby on Rails or python.
If people keep demanding PHP, PHP will continue to exist. Simply the fact that Facebook uses it (quite well I needlessly add) says way more than fan-boy hype monsters of other frameworks or languages.
What it comes down to in the end is, are you productive with it, and does it solve your (the clients) problems?
@Scott: Since I have only been playing with PHP a few days, I may be wrong, but as of 5.3 there is support for closures, making my reference ironically inaccurate (although, it still serves its purpose).
http://wiki.php.net/rfc/closures
PHP is easier to get kick started, thats the reason a lot of ppl seem to think they know it. And i guess thats the only valid reason I saw in the post to switch to php for your ‘wordpress’ like project.
PHP will still remain relevant, and its got its own merits. If you are a good programmer, ruby will delight you but you can still make the magic happen in PHP.
Rest of arguments are valid, buts its not that hard anymore. Its just a matter of people educating themselves. I deploy most of my rails app like i would my drupal or wordpress app
.
@Rishav: Some people in HN agree with you. I should have mentioned that I do use Capistrano for my Rails projects. However, for small projects, cap seems tedious.
Also, as I stated in the footnote, I have deployed via passenger. That being said, I still think PHP beats passenger — although I cannot identify why I think that is true.
@Scott: Just because you are productive with something doesn’t make it good, and just because it is the best tool for the job does not make it elegant.
I would suggest you learn a few more languages before you start making statements about them. In this case, the author chose php for its deployment story. In a case where he was deploying a site to his own servers he may have chosen rails. In a case where massive concurrency was an issue, he may have chosen LIFT. In a case where lots of number crunching was involved, he may have chosen JSP.
Like the author, I know about 7 languages fairly well, and like the author, ruby is pretty much my default choice. That doesn’t mean that I will use it in places it doesn’t make sense, but it does mean that I consider it one of the most elegant languages out there, and will use it any time I can get away with it. I don’t think that makes me a fanboy.
I am at a crossroads on a project. Implemented a bunch of initial code in PHP (core background is LAMP stack and lots o php past 5 yrs).
I consider myself to be open minded and when one of the guys on this new project suggested/demanded : ) Rails I entered it with an open mind, always nice to learn something new, and ultimately I wont be managing the code day to day.
Started out good enough last week, liking Ruby as a language, got Rails running on my machine (windows user) with the exception of MySQL support (64 bit support lacking).
Decided to go with Merb after reading its benefits over the “bloated” rails framework and quickly realized how immature Ruby community is when it comes to windows support, which obviously is a key thing for enterprises. The more I have been digging I cant imagine how Ruby will get to be a really mainstream language.., at least not for several years, which is a shame b/c it IS a cool language.
Could you disclose which area your open-source project covers?
@Rick: In about a month, yes.
I am a fan of the ‘right tool for the job’ mentality.
PHP is a great tool, with much room for abuse. So is C. Both have pros and cons.
I tend to write tools with very high performance requirements (but low maintenance requirements) in a low level language like C. I write very few of these tools, but they tend to have long lifetimes in production.
Web applications, small CGI apps, console utilities, well, these can be written in just about any language, but these are usually Perl or PHP. Usually the choice of tool in this case depends on the language of other tools in the environment, and what you have to interact with. If you are using a database with only JDBC connectivity, PHP may not be the best choice, but that is just one example.
I find it is much easier to write unreadable Perl code than PHP code.
@John … hm you’re in my google calendar
@Rick: Sweet.
I write all my web development code in C. Believe.
It is not easy for any web developer to skip that magic 3 chars PHP. I thing it is a matter of love adn respect to that collective efforts and imaginations of those who make this wonderfull tool possible.
PHP was and still is THE language for web back-end development. I don’t get it why would anyone develop web apps with C, except for Facebook-sized and corporate projects.
# PHP > Ruby
Have you tried coldfusion? Coldfusion > php
When it comes to immediacy, Heroku is as immediate as web development can get, and the free stack is much more powerful than many think.
If you are looking for a PHP framework that covers most of the same basics as Rails and has excellent internal code, I suggest Kohana.
Disclaimer: I am the lead dev of Kohana.
@Matt Briggs: To say I don’t know other web environments would be presumptuous and blatantly incorrect. Should I make a similarly vague assumption that just because you disagree with me you use Rails?
In fact I’ve used many languages for many reasons, ranging from, but not nearly limited to, PHP, RoR, Java Servlets/JSP, .Net, and that simply in the web domain. (And to assume that you think Java is a great environment for ‘number crunching’ makes me question your position entirely).
That said, I will agree with you that just because you are ‘productive’ (and that definition may vary depending on the developer), doesn’t mean you’ve chosen the right tool for the job. I’ve see plenty of programmers create a nail out of a problem simply because they only know how to use a hammer.
In all, the “which web language/framework do you use?” debate is as pointless as is DirectX/OpenGL flame war. It will always come down to the specific problem, client, timeline, skill set, deployment environment etc.
I choose PHP for my current projects because the development cycle is quick, the projects are small, and I can deploy to a wide variety of hosts just the same – rsync.
(As a completely separate side note, comparing RoR to PHP is pointless as RoR is a framework an PHP is a language. That would be similar to comparing DirectX to Ogre).
Great way to put it. After spending a month learning rails and eventually going back to PHP I share your sentiments. Learning “the Rails Way” gave me a new perspective on PHP Frameworks.
Also: PHP 5.3 is mega sexy.
Developing a website from scratch in PHP is pretty tough nowadays, there are so many security issues that you have to watch out for.
I just start with Drupal, which handles the common features (like handling user logins) and they have many more eyes to watch out for security issues.
Then using Views & CCK, a custom theme and possibly custom drupal modules you can create just about anything.
You can write complex website and frameworks without Rails easily.
I have done so. I simply can not say the same about PHP.
PHP has other advantages such as being available almost everywhere on the www.
But as far as language beauty is concerned, ruby beats php easily.
“Sure, but Pear works.”
Kinda, in the “this module is written to support php4, and has runtime evals and other bloody horrible practices.”
“Moreover, integration with PHP is often easier than it is with rails.”
For you, if you’re using a library someone else created, maybe.
When was the last time you noticed that popular api or library lacked a PHP interface? Most sites release official PHP libraries (s3, ec2, facebook, gdata, …)
There are more libraries for Perl than there are for PHP and the average perl programmer knows what a closure is.
Ruby has a massively better and modern syntax. But, Perl is literally stronger in every area than PHP. Use Perl and Moose which effectively gives you all that you’ll miss in the migration from Ruby plus some, and check out the Catalyst framework.
It seems every few months somebody makes a “going back to PHP post”, tempers get flared, and the old arguments get rehashed. Nobody cares.
Ruby works for many. PHP works for many (more). Pick your poison and build your apps. Nobody really cares what you use.
You cited Facebook,
Facebook uses python !