Friday, January 16, 2009 #

Ruby is Weird

So I was at CodeMash last week. The first thing I did at the pre-compiler was go to the Ruby 101 session presented by Jim Weirich and Joe O’Brien. The way the session worked was that they gave people everyone project code which contained a customized unit test suite that would stop running at the first failure and a set of unit tests that were all failing. Each test was intended to teach one aspect of the language.

I have to say, I thought it was a great way to learn a programming language. It got me reading, modifying and writing my own quickly. It’s a pretty novel idea in my opinion and it worked really well. It was definitely worth heading down to Sandusky a day early. Expect to see me at CodeMash and the pre-compiler again next year.

Anyway, from the perspective of someone who has worked in C# basically my entire professional career, learning Ruby is a big change of pace. After I finished the unit tests that Joe and Jim had prepared for the Ruby 101 session I started working on the “extra credit” they provided, which was to implement a version of the game Greed.

As the post suggests, ruby is weird. Take this code, for example..

turnNumber = 1 
until last_turn? 
    single_turn turnNumber 
    turnNumber += 1 
end 

Let’s see.. I created a variable without specifying a type or even var. I’m using a control flow statement called “until”, a question mark in a method name, two method calls with no parentheses and no semi-colons or curly braces. The same thing in C# would look something like

int turnNumber = 1;
while (!IsLastTurn())
{
    SingleTurn(turnNumber);
    turnNumber++;
}

Obviously ruby’s syntax doesn’t get as hung up on ceremony as C# but that’s not what’s really interesting about the language to me.

What I find really interesting is the way that classes and methods work in ruby. The method_missing allows some really interesting behavior. While I think RhinoMocks is a great piece of software, it seems like it would be pretty trivial to write a mock in ruby. And you don’t even need an interface.

Starting to learn ruby has reminded me how much I enjoy learning a new language. I' think I might start playing with ruby on rails. As a professional web developer, I feel like I’m missing something but not knowing much about rails.

If it’s as great as everyone says it is I need to learn it so I can steal as many ideas as possible.

posted @ Friday, January 16, 2009 7:51 PM | Feedback (4)