Ruby on Rails – From a Java Developer’s Prospective

So, I’ve been using Ruby on Rails for about a year now. It was the language of choice at Rosetta Stone so I had to learn it on the job. It’s an interesting platform, especially for people like me (I have an extensive Java/J2EE and .NET background).

I have to admit, when I first started with RoR, I didn’t really like it. The language seemed goofy and there seemed to be alot of “magic” that happened behind the scenes. Java and .NET developers are used to controlling everything Via XML or code configs 🙂

Three of the weirdest things I’ve gotten used to are:

  1. Just like Javascript, Ruby isn’t a typed language – all variables are declared without a type – including Functions – they have no type whatsoever. You don’t specify what a function is going to do except in its implementation. This is what a Ruby function looks like when you want to return a String:

    def HelloWorld
    "Hello World"

    And when you just want to perform some logic, without returning anything:

    def AddSomeRandomNumbers(a, b)
    sum = a + b

    There is no such thing as “void” or “return”. These keywords or their equivalents don’t even exist in Ruby!

  2. The lack of semi-colons , parenthesis, and braces. You don’t need to end a line of code with a little ;. The semi-colon does not exist in Ruby, at all. You also don’t need to enclose statements with parenthesis. My first few days of writing Ruby code I found myself adding these little characters anyways, out of habit – only to be made fun of by co-workers :)An IF statement typically written like:

    if (variable == true)
    value = someValue;

    Can simply be written like this in Ruby:

    value = someValue if variable == true

    Note the total lack of parenthesis, semi-colons, and braces.

  3. The Unless statement is made to confuse people. Check this out:

    string = "cool" unless Month == "October"

    This statement only sets the variable ‘string’ to “cool” if the Month is not “October”. Its like using the “!=” operator, except you have to read the “Unless” keyword. Totally weird and confusing at first.

So a year later – I’ve gotten used to the weird things the Ruby founders have put into the language. I actually do think that it is quicker and easier to write the same type of code in Ruby vs Java or C#. Performance is a totally different issue, but speaking from a pure code productivity standpoint – its my opinion that Ruby has achieved its goal for ease of development.

Ultimately, the “looseness” of the language makes it easier to WRITE code but harder for developers to UNDERSTAND someone else’s code.

I’d love to hear what your experiences are with Ruby. Please leave some comments!

First Post!

I decided to start a blog.  It seems like a cool way to share some thoughts on things that interest me. I’m a Web Applications Software Engineer so I’ll try to focus the blog on related topics. Mostly Ruby on Rails, Java, and related things 🙂

That’s all for now … more to come later!