Tuesday, July 31, 2007

Ruby? hmmmm!

Well, another day with Ruby and here is something that was bothering me right from day one.
If you have ever written something in Ruby, you might have noticed that Ruby is SLOW. I would go ahead and say that it is "pretty darn slow". May be this is the price you pay for all that 'syntactic sugar'?
A very simple bench mark - I created a class, added a to_s method, tried to print contents of the class, It took 10X time compared to Java 5 & Java 6 on Windows. 

Oh by the way, I have to check out if this is same in OS X too.

Monday, July 30, 2007

Attempts to learn Ruby

Long time since I seriously looked at a programming language. I was thinking of which one to select. Given all the hype around Ruby, I thought of studying Ruby in a structured way. Why I say "structured" is, because I have had enough dabbling experience with Ruby already. 
So, I came across this very interesting construct called "symbols" in ruby. It is just like a variable, a name that starts with a colon - ':'
For a clear understanding I read through a lot of forums about symbols, and all I found is that this is a very confusing idea for new comers. As you can see, Ruby symbols generated a 100+ post thread on the ruby-talk@ruby-lang.org mailing list - and some of them are really heated.
Anyway, my take for now about symbols is:
In ruby, if you say, "some double quoted string" a thousand times, ruby creates different objects for it. But if you use a "Symbol"-ised reference to it, as :"Some double quoted string", it is a symbol and it is created only once. This seems to be useful in places where you create hashes.
Anyway, I agree, this is not a very satisfying explanation of Symbols(or at least their usage). But for a Ruby newbie, this should hold good enough.