I began my computer consulting career in 1999 as a PHP programmer. For several years, all of the Web sites I created were written in PHP. (I have done a couple of ASP.NET sites, and although I find the technology and the development tools to be impressive, the requirements that you develop and run ASP.NET on Windows is a non-starter for me.) In 2005, while at the Apple Worldwide Developer Conference, I first played with the Ruby on Rails framework, released a couple of months earlier. So, like many people, I came to Ruby after seeing how brilliant the Rails framework was. At that time, there really were no PHP frameworks that were comparable, although perhaps the Zend Framework, among others, are close enough today. I wanted to talk a bit about how I see PHP and Ruby, but first, a discussion of frameworks…
Some people have asked if Ruby on Rails really is better than PHP. This isn’t an appropriate question, however. PHP is a programming language that can be used for many purposes, by far the most common of which is development of dynamic Web sites. (PHP can be used for other purposes, including creating command-line utilities or even graphical applications; it’s just not used for those purposes nearly as often.) Ruby is also a programming language that can be used for many purposes, perhaps most commonly for command-line and system utilities. In part thanks to eRuby (Embedded Ruby), Ruby can also be used for Web sites. Conversely, Ruby on Rails is a framework written in Ruby. A framework is simply a library of existing code that can be used to facilitate application development. Ruby on Rails is Ruby’s most popular Web development framework, although not the only one. For PHP, popular frameworks include PEAR and PECL (depending upon how you define “framework”), Symphony, Cake, and Zend. So any comparisons to be made aren’t between PHP and Rails but rather PHP and Ruby or the Zend Framework and Ruby on Rails. Over time I’m going to make this second comparison myself and post the results here.
As for PHP versus Ruby, I’ll say that subjectively, PHP is my first love and is still the language I turn to for updating existing Web sites (rather than rewrite them in Ruby) and for creating simple Web pages. I think PHP is really easy to learn and use, especially for those purposes, and both writing in it and debugging it is rather easy.
Ruby is kind of amazing. It’s a pretty impressive language with lots of great features. As an object-oriented language, PHP can’t really compare. The ability to alter existing classes–even those built into Ruby, like String or Array–on the fly is fantastic. And I find installing and using RubyGems to be easier than PHP’s PEAR or PECL. When I’m working with PHP, one thing I miss is Ruby’s irb, the command-line Ruby interpreter that can be used to test small bits of code.
I’ll add some more specifics in future postings but I wanted to put this basic info out there immediately. I will also say that I put little faith in discussions of security or performance when making comparisons. A bad programmer can make really insecure applications using a very secure technology so I think that saying any language or technology is more or less secure is inappropriate. As for performance, there are so many variables there that, again, just saying X is faster than Y is not often meaningful. One of the argument’s for using Ruby is that it’s very quick for you, the developer, to use, and your time is far more critical than the computer’s.