Three less-than-obvious reasons why Ruby is the bomb

Instead of putting out “yet another top 10 list” of superficial, syntactical reasons why I prefer coding in Ruby, I thought I’d touch upon a few lesser-mentioned features that I miss big-time since picking up PHP:

Gems – shiny package management

RubyGems is a simple, easy to use package manager that gives you instant access to over 1500 Ruby libraries (called ‘gems’) via Rubyforge. Compare that to PEAR, PHP’s “Extension and Application Repository”, whose official channel contains less than 200 endorsed packages. It works something like this:

gem install rails --include-dependencies

To be fair, PEAR works very similarly, but it lacks one critical feature I’ve come to love with Gems – the ability to manage multiple versions of the same package. You can pick and choose which gem version to load from inside your app (examples below). This makes life much easier if you’re managing a bunch of different apps on the same machine, all with their own dependencies.

gem ‘rmagick’, '>= 1.1.3' # Only use rmagick with versions >= 1.1.3
gem ‘freshbooks’, '= 0.2' # Version 0.2 only

Did you know: There’s a book dedicated entirely to RubyGems.

Otherworldly code style consistency

Rubyists are staunch defenders of coding standards. After a year of developing with the language, I’ve yet to come across a single library or code example that uses either camelCase naming convention, tabs instead of spaces, or non-standard bracket use. It’s not that I particularly care for one set of rules or the other; it’s just refreshing to see the same familiar coding style every time I step into a new piece of Ruby code.

With PHP, you’re never sure what you’ll get. For example, SimpleXML, PHP5’s standard XML library, uses camelCase function names, whereas most “old school” PHP functions side with underscores (i.e. array_push).

Side note: I just discovered Ruby-SDL provides both Ruby-style method names and their C-style CamelCase equivalents, keeping both Rubyists and old-school SDLers happy. Very cool.

Plugins for everyone

Since you can modify existing classes at runtime in Ruby, adding support for extensions or plugins to your applications is trivial. If you’re writing software in PHP, you need to write hooks ahead of time, or else your users will need to modify the source themselves. The worst example of this is phpbb, whose extension system is a series of insert/remove code statements – yikes!

# my_app.rb
class SomeClass
  def some_method
    do_something
  end

end

# my_plugin.rb
class SomeClass
  def some_method
    do_something_else
  end
end

Looking for more?

If this list seems a little short, feel free to peruse the following fanboy articles:

Commentary

I share the same joys with the reasons listed above. I simply love that Ruby speaks like English. It eliminates the verbosity and unnecessary for elegance. The fact that I can just type in ‘if user.logged_in?’ after creating a boolean ‘logged_in?’ method is simply beautiful. It beats using ‘if $user->loggedIn() {...}’

Ruby is elegant and complex at the same time, and that is what makes it a joy to work with.

Comment by Nate Klaiber on August 15, 2007