Geeks With Blogs


View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites

Anthony Trudeau

I posted a few weeks ago about not being able to find time to learn a new language.  Well this week I got a beginners book on Ruby for my birthday; and I've decided to make a concerted effort to find the time -- even if it's just a bit of time.

Ruby is an interesting language.  It bills itself as being expressive and so far I have to agree.  Although there are some notable exceptions.  For example, I don't think it's very clear that the following line of Ruby code changes the elements in the array for each element.

[1, 2, 3, 4].collect { |element| element * 2 }

On the other hand I really like how the regular expressions are integrated within the string handling -- C# and other .NET languages use the RegEx class.  For example, in Ruby I can replace a call to a static Match method on the RegEx class with the following (it's definitely more expressive).

puts "String has vowels" if mystring.match(/[aeiou]/)

Typing is probably my biggest concern.  I'm used to strongly-typed languages.  When I was programming Visual Basic I always loathed the Variant, and for that matter I'm a little squeemish on using the Object type (I heart you Generics).  Ruby is not strongly-typed, but it seems to be dynamically typed rather than weakly typed (what I've read so far hasn't elaborated on it).  The following two code examples illustrate why Ruby isn't weakly typed.

'VB for Applications example
Dim x(2) As Variant

x(0) = 1
x(1) = 2
x(2) = 3

If x(2) = 3 Then Debug.Print "x(2) = 3"
If x(2) = "3" Then Debug.Print "x(2) = '3'"

The example in VB for Applications will display both messages, because the integer in the array is coerced into a string for the comparison.

#Ruby example
x = [1, 2, 3]

puts x.include?(3)
puts x.include?("3")

This example will display true and false for each line respectively.  There doesn't seem to be any evil type coercion.

At the fear of looking like a complainer I have to say my first impression of Ruby is with the tools they provide.  Specifically, fxri which is first day program simple looking.  I like that you get some documentation there (since there is nothing like Intellisense anywhere), but why does it have to load every single topic into the pane; and why does the pane indicate that there are 13,438 of 13,437 entries... 

Overall, I'm enjoying the experience.  I'm not sold on the language and at this point I'm not sure what it brings to the table for me as a C# developer; but I've only been looking at it for a few days so the jury is out.

Posted on Friday, March 20, 2009 4:01 PM | Back to top

Comments on this post: Learning Ruby: First Thoughts

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Anthony Trudeau | Powered by: