Which is “better” for developing web apps – Ruby or PHP? I recently saw a question on LinkedIn which inspired me to add my two cents to the discussion…
The key difference in the languages (Ruby vs. PHP) are the level of “object-orientation,” and (obviously) syntax. Ruby was designed from the start (~1993) to be an object-oriented language (EVERYTHING is an object) while PHP was, until recently (v5.0 – 2004), a procedural language (an example would be PHP v4.x’s use of the class name as a method for initialization vs. PHP 5.x’s use of __construct). As a long-time PHP programmer who migrated to Ruby in 2006, I prefer Ruby’s implementation of OO over PHP’s. I also prefer Ruby’s syntax AND coding best-practices over PHP’s.
There are many good Model, View, Controller (MVC) web frameworks for both languages. PHP has CakePHP, Code Igniter, Akelos, Symfony, Zend, etc… Here is an excellent list of web frameworks for PHP: http://www.phpwact.org/php/mvc_frameworks. Ruby’s MVC frameworks include: Rails, Merb, Sinatra, Ramaze, Nitro, etc… Here is an excellent list of Ruby web frameworks: http://accidentaltechnologist.com/ruby/10-alternative-ruby-web-frameworks/.
In my opinion, there are two keys to selecting a web framework. First is the Object Relational Mapper (ORM) – how the data is abstracted, and testing. In my early days writing PHP code, I found myself writing a lot of (repetitive) SQL queries to access data. With an ORM, it is easier because the queries are abstracted out. While this may be “slower” than directly accessing the data with SQL queries, it saves a LOT of programming time. The bonus to using an ORM is one can ALWAYS write a custom query if needed. Testing is also HIGHLY recommended and attractive… before I became a test-aware, I cannot tell you how many times my code would break after I made (what I thought) was a small fix… this can be avoided by testing the public-facing code. Do not commit (version control) or deploy unless all tests pass!
My specific recommendation for a PHP-based web framework would be Symfony (http://www.symfony-project.org/) because it uses Doctrine ORM (http://www.doctrine-project.org/), is packaged to be used as a library (ala PEAR) – meaning one code base can natively support many instances, and has a decent test suite. For a Ruby web framework, I prefer Merb (http://merbivore.com) because it is “lighter” than Rails, is ORM agnostic (you can choose from Datamapper (http://datamapper.org), Sequel (http://sequel.rubyforge.org/), or ActiveRecord (http://ar.rubyonrails.org/)), supports threading (concurrent processing), and natively supports testing (Rspec – http://rspec.info/).
If you are a PHP programmer, I would recommend you start learning Ruby and use Merb as your web framework. While it seems there is a relatively steep learning curve, you will find your development time will dramatically drop in the long-term using Ruby / Merb / Datamapper.
Comments
Comments are closed.