I’m often surprised by the number of people that still have not heard of Ruby on Rails.
In case you haven’t heard of Rails, it’s a framework built upon the Ruby programming language. Ruby is completely object-oriented and suitable for many platforms and purposes. It can be run on all the major operating systems, and comes preinstalled on most modern flavors of Linux. Rails is a framework that makes developing web applications in Ruby take less time once you get past its learning curve.
To date, I’ve programmed in several languages. I wrote a web spider in Java, built a very popular tech support portal in ASP (in the top 3000 of Alexa’s ranking), have written countless export and database administration scripts in Perl, and have written a lot of applications in PHP such as a point of sale system, photography gallery, online appointment system, employee management system, file management system, and numerous other websites over the last 9 years.
I’ve felt that PHP has been somewhat stagnate for the past couple of years. Sure, there is version 5 that does a little more with objects and classes, but my impression is that the majority of PHP sites still run on version 4, which was released in May of 2000 even though version 5 came out in July of 2004. No doubt, PHP has been adding support for various extensions, and they’ve added additional functionality in their many sub-releases, but it’s essentially the same as it was 7 years ago.
In the first draft of this document, I stated that PHP replaced Perl, and Ruby on Rails will eventually replace PHP. Technically, that’s incorrect. PHP hasn’t replaced Perl. Rather, I believe that the developers of PHP based a lot of their functionality on Perl, but changed a few things based on what they intended to be a better system for web development. This is only my opinion, so please take that with a grain of salt as my experience developing web applications in Perl is limited.
What I can tell you with certainty is that the developers of Ruby on Rails did their homework. They’ve taken a look at all of the existing web development platforms such as Java, PHP, Perl, ASP, ASP.NET, Coldfusion, Python, etc and have a really good idea of the things web developers of these platforms had to do over and over again such as creating forms or writing dynamic database queries with optional fields in the where clause, etc. Either through personal experience or by viewing other’s code, I’m not sure, but they also knew that most ASP/PHP style sites with embedded code within HTML causes a lot of headaches on larger sites because it’s a lot harder to maintain and test effectively.
From there, they created a framework on top of the Ruby language that forces code to be separated into 3 distinct areas: The models contain database info, the controllers contain application logic, and the views contain the html templates. This makes applications more structured and easier to maintain. They also created a set of libraries that make other aspects of web development easier to deal with. ActiveRecord does a really good job of abstracting database queries. Not only does this make creating queries easier, but it makes it so the application will work for a number of different database servers without adding a bunch of kludges for each database server. There is also a feature called routes which reduces the need for GET variables in a URL string. Instead, URLs follow folder style syntax, which has been claimed in many places to be more search engine friendly.
Ruby on Rails has caused a stir in the web development community, and many businesses are moving from PHP development to Ruby on Rails development. Why? Because once you know Ruby on Rails, you can program an application faster than PHP.
In response, the PHP community is trying to catch up, but they have a long way to go, and in my opinion, they’re going to fall on their face. They aren’t unified. They aren’t creating 1 framework to rival RoR or the other main platforms such as ASP.NET or Java. I did a couple of searches and found over 40 different frameworks for PHP.
With over 40 to choose from, how can a person decide on the right one? There’s definitely a learning curve involved, so who has the time to learn 40 different frameworks? How many people are getting turned down for jobs because they know PHP, but not the right framework that the business is using? How many of these frameworks are going to still be supported in 2 or more years? The worst part of it is that many of the PHP frameworks (CakePHP comes to mind) openly claim to be a Rails clone. Why use a clone when you can use the real thing?
“United we stand, Divided we fall”.
Ruby on Rails is united. There is one framework to learn and enhance. PHP is divided with over 40 frameworks.
I still program in PHP for legacy sites, but new sites are being done in Ruby on Rails.
Ruby on Rails is not all fluffy clouds, girls fanning you with giant leaves, or whatever your personal paradise is, however.
It’s a huge pain to get the server set up just right, and overall, it isn’t as fast as raw PHP (or raw Ruby for that matter). Typically, the lower level your code is, the faster it is because it doesn’t have to compute as much. Rails has several layers of code sitting between your own code and the processor. It also has a pretty steep learning curve unless you’ve already programmed using a framework and are familiar with object oriented concepts. It’s also really new, which means that there isn’t a lot of support on the web for Rails, and many of the standard apps that people can expect to get on PHP aren’t available yet such as free forums, ecommerce sites, etc. There are a few available, but they aren’t developed as fully yet. It’s also more difficult to find a hosting company that supports Rails unless you have a dedicated server and do it yourself. They can be found, but there is only a handful so far.
Rails does provide some great features to scale a site, however. Sessions can be stored in a database, which makes it possible to have one web application span multiple servers and not worry about sessions getting lost. There’s support for caching at a page level and at a partial level (a partial in Rails is like an include or require in PHP). Currently, the best server setup uses a combination of Apache and Mongrel, a single-threaded web server designed to handle Rails applications. Apache’s proxy load balancer makes it possible to pass connections to any number of instances of Mongrel whether on the same or different servers, which makes it possible to scale a site quite easily.
Frameworks are the way to go, if you want the structure of your code to be standard and thus easier to get a new developer ramped up and productive faster. Ruby on Rails is ahead of the game and PHP is trying to catch up. Every day, people are switching from PHP development to Ruby, and unless they can come up with a unified framework to rival Rails, I believe they will lose a large percentage of their development community.
I’ve written a 2009 update to this article, also titled Ruby on Rails vs. PHP on a social network site that I wrote using Ruby on Rails.