Monday, July 09, 2007

Ruby

After 3 months with Ruby, I think it's a great language. It may not be as fast as C or Perl but it is very developer-friendly. It's 100% object oriented. That means everything is an object and hence everyobject can be manipulated by some very useful set of methods that are provided with the language
So you can say something like this
12.next => 13
12.remainder(5) => 2

It also supports some of the very powerful features of Lisp(Greatest language ever !) like unnamed functions, blocks, iterators etc

"A quick brown fox jumped over a lazy dog".downcase!.split(//).sort.uniq.each {|char| print char+" "}
gives
a b c d e f g i j k l m n o p q r u v w x y z

Being 100% OOPs is one of the strongest features of this language

1.upto(10){|i| puts "9 X #{i} = #{9*i}"}
will give you table of 9
9 X 1 = 9
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45
9 X 6 = 54
9 X 7 = 63
9 X 8 = 72
9 X 9 = 81
9 X 10 = 90

It offers "minimum surprise" to a newbie and the code is very easy to read.

Though there are some downsides also as it is interpreted only language and can be slow. But come Christmas 2007 a new ruby version is being released which hopes to solve this problem to some extent.

No comments: