Earlier this week I was hanging out with a friend talking about a project he was working on and I decided to poke at it a bit with him, and as such got my first hands on experience with Ruby on Rails.
Ruby on Rails or RoR obviously has huge buzz and is a very popular web application development framework lately. Lots of people have praised it and lots of great sites have been built using it. I’ve never bothered to learn it myself for a few reasons. First I’m a Java guy (ATG and Seam) and have been for years. Given limited time and limited brain capacity I’d rather learn more Java/Java Frameworks/etc… than try to learn a whole new language. Secondly many trusted friends advised me that while RoR does somethings REALLY well and makes some things REALLY easy, once you need to try to break outside of the pre-imagined structure/features that RoR provides out of the box, things rapidly go downhill. Those reasons aside, the high level of buzz has meant I’ve always been somewhat curious, so this opportunity to finally get my hands a little dirty with RoR was welcome.
Getting started with RoR on Mac OS X is very easy. It’s pre-installed and works right out of the box. However after upgrading Rails and the gems I ran into a known blocking bug which after some Googling I was able to fix by downgrading rake to 0.8.7 in the Gemfile. So not a 100% smooth start, but not too bad.
The Rails generate scaffold commands make it very easy to create a data object, the related schema changes (managed through the rake migration mechanism), and related CRUD pages and controllers. You can be up and running very quickly and creating, browsing, editing, and deleting records. This can make it very easy to get a basic application laid out, and provides lots of plumbing automatically.
I didn’t get much farther than some simple controller modifications, outbound e-mail sending, etc… so I’m far from a real RoR developer. However I ran into enough pain points so far that I don’t think RoR is for me. I don’t want to start any language/framework wars, but here is what I ran into:
A lot of the “magic” seems great at first, but as soon as you want go outside of the box or tweak how things are working, it becomes a massive liability. For instance when using the generate scaffold command to create data objects you can setup relationships/foreign keys by passing in a column name that matches the form OtherClass_id:integer, which will be interpreted to be a FK association to the other class’s id column to join the objects. This is great. However, what if you want to add two relationships to the same Other class? For instance an Message has a Sender and a Recipient, both of which are Users. I can use user_id:integer for one, but how do I do the other? How do I use column/property names that don’t fit that naming convention, for instance I’d want sender_id and recipient_id. None of the getting started guides I was able to find covered that. Googling for things like “scaffold multiple foreign keys” didn’t answer the question, etc… I’m sure it’s possible, but finding out how wasn’t easy, and the default way hides and obscures the actual plumbing so it’s not easy to figure out how to make simple changes or additions.
Data object classes in the app/model area all extend ActiveRecord::Base and as generated by generate scaffold are completely empty. There’s no clue or indication of the fields, any logic available, any relationships, property types, etc…
Emailer classes use magic mappings between method names and e-mail templates. Because it’s “magic” I have no idea how to change a template file name if I wanted to. App/helper classes are created, but they’re empty, so I have no idea what they are doing, or meant to do. And so on. If I was an expert RoR developer I’m sure I’d know, or if I read a few books I’d understand, but starting from scratch and trying to learn as I go, it proved very frustrating.
The much touted RoR Community proved to be more of a liability than an asset to me. Especially when combined with the many, rapid, backwards incompatible, RoR releases that have come out so far. When looking for information, guides, and answers related to RoR you end up finding things spread all over: blogs, forums, mailing lists, Ruby sites, RoR sites, groups, etc… Most of these posts/documents refer to older versions of RoR. Most of them don’t have dates or specify which version they are working with. Many questions on forums are unanswered. The end result is you find what you hope is a reasonable solution for an issue only to find that the code sample or directions are written for a previous version of RoR, and trying to follow the instructions or paste the code in the current RoR version results in weird errors or worse.
Each new version of RoR seems to massively change and/or break common APIs and change how things are supposed to be done, etc… I ran into several situations where it seems like a method was renamed, with no backwards compatible alias left in place, for no other reason than they wanted to change the name, which breaks older code for no real purpose.
I’m also not a fan of weakly typed languages. Strongly typed languages provide compile time validation, IDE auto-completion, and easy to navigate API documentation. With larger, more complex projects, or projects involving many developers, or projects utilizing many 3rd party libraries, these advantages become significant in my opinion.
So from my standpoint, JBoss Seam provides most of the advantages of RoR, including several improvements, without many of the liabilities. Plus it’s in Java which is my strongest programming language. I’ll stick with Seam, but I’ll still respect the creations of folks who use other tools, including RoR.
Swedish Translation courtesy of Andrey Fomin: http://www.pkwteile.de/wissen/foersta-borste-med-ruby-on-rails
Leave a Reply