I've been a Perl user for a very long time. How long? Let's see... probably 12 years. I'm fairly certain I first touched Perl back in 1993 to analyze the logs of the NCSA web server back when I was in college. Yet in the last few weeks, I've become extremely attached to Ruby for things I would normally do in Perl. Ruby has just a nice, clean object-oriented environment. Writing OO Ruby code is straight forward if you come from a C++ or Java background. There's no blessing of objects, choosing the object representation, crazy things to make sure inheritance works, or trying to use Class::MethodMaker to make it all just go away.

So why the switch? I decided to learn Ruby on Rails so I could hang out with all the cool kids. Of course, to learn Rails, I needed to learn Ruby. In the end, I not only walked away impressed with Rails, (which will have to wait for another blog entry), but I walked away very happy with Ruby. Part of my success of learning is due to the "Pickaxe" book, which is just a fantastic book. If you have any interest in learning Ruby, buy this book. A few really cool features of Ruby (besides the simplicity of writing OO code) that really stick out to me are:

  • The concept of attributes, and method names ending in "=". This kind of code is just way cool:
    class Person
      def name=(name)
        # ...
      end
    end
    
    person = Person.new
    person.name = "Matz"
    
  • Closures. Martin Fowler has a good explanation on what is so cool about closures, with examples in Ruby.
  • Absolutely everything is an object, including types that are typically primitives, such as integers and floats.
  • All classes are open. There's no such thing as a Java final class. While this means you can actually override the plus operator for integers to redefine math, it also gives the flexibility to add methods to built-in types when needed. Surprisingly, I've already come across a case where that made my life easier.

So why Ruby instead of Python? Well, as I mentioned the original goal was to learn Rails, so Python wasn't exactly an option. But I've tried to learn Python in the past because some coworkers have been so gung-ho over it. But for some reason, Python never really clicked with me. When I needed to write a script, I'd try to do it in Python first, but always ended up going back to Perl because I just couldn't figure it out. Plus, the Python book I have, O'Reilly's Programming Python, was really awful. I can't remember the details, but the structure and tone of the book, again, just didn't click with me. I should probably give Python another chance, perhaps with a better book. But now that I know Ruby, I don't have as much as a compelling reason to learn Python anymore. The only draw for Python to me now is PyObjC, but I'm hoping someone will come out with a good Ruby to Objective-C bridge first.

So in the end, if you're looking to learn something new, spend some time with Ruby, especially if you're a Perl die-hard. In the words of Tim Bray: It sure looks like more than a fad to me.