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:
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!
- 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.
- 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!