First brush with Ruby On Rails

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


Posted

in

,

by

Comments

2 responses to “First brush with Ruby On Rails”

  1. Devon Avatar

    A few comments on a recent HN post seemed relevant so I’ll share them here:

    http://news.ycombinator.com/item?id=2610274

    “RubyGems 1.8.5 actually breaks Rails 2.3.11. Just to be really clear there: the package manager breaks the 4 month old release of the most important framework for that language, on a branch that until rather recently was still the preferred production stack (and is still used by a bazillion websites).
    I was flabbergasted. Really? Nobody thought to check to make sure the package manager release doesn’t break Rails 2 completely? I’m glad to see Loren and crew step up.” — wheels

    http://news.ycombinator.com/item?id=2610425

    and

    “Don’t forget rake. The latest version of rake broke all versions of Rails (don’t know if this got fixed yet).” — jcapote

    http://news.ycombinator.com/item?id=2610448

  2. MarkoD Avatar
    MarkoD

    I fully agree with assessment. I think RoR is cool for people who just want to get something done in less then 5 days with goal of getting it done as primary objective. All obstacles will be handled according to RoR best practices – usually simplifying requirements. We do live in world now where everybody makes something on Web, so this does have its audience.

    Magic is nice. Seam also has a lot of magic but that magic is well explained and one can adjust it to his needs. Also there is seam-generator which is excellent tool and in one of the projects I gave task to junior developer to focus 2 weeks on adjusting code templates to our architecture, layers, custom logic and we got from that point on fully generated admin of several hundred tables include 1:1 and 1: many relationships, validations …
    So, if one has urgent need to generate code and pages from db easily, there are many ways to do it … even out of box one.

    Anyway, I think there are 2 sets of RoR fans:
    1. one that see it as great tool to get something done and had positive experience with it with their scopes and requirements. From our (ATG/Seam) perspective … RoR can not solve 1% of problems we encounter.
    2. programming concepts fans – it is interesting to apply a bit different paradigm, but is it more of an experiment or really productivity?

    I am playing around with it a bit just for fun and would not use it for project unless there are some good reasons that I could justify to anyone. Would more consider maybe Grails as an alternative to RoR in some simple web project if requirements would fit what tools offer for agile approach based mini projects.

    Notes:
    1. one can not escape days/weeks/months/years of learning if it is required and there are no shortcuts.
    2. I think RoR is problematic from documentation perspective so not reliable component sort to say
    3. Would never put Java and RoR in comparison :-)

Leave a Reply to MarkoD Cancel reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com