Sunday, September 24, 2006

Ruby, is it worth my interest?

Recently, I read about new scripting language from Japan - Ruby. I already know quite good Perl, so I decided to read a little more about this, because what I had read, expressed very good opinion about this new language.

Ruby, as its homepage says, is: "the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable ... and free of charge".

On the grounds of above, I decided to give it a try.

Installation

I was surprised to find out that my Mac X Tiger has embedded Ruby interpreter. So users using newest Mac's don't have problems with installation. Despite this, i decided to install it on my Ubuntu Breeze, by running sudo apt-get install ruby. As a result, Ruby was installed on my Linux.

My first script

To get an idea about this programming language, I decided to write a little program, that reads two text files containing mainly numerical data, organized into tables (tabulator as separator between columns). Below is an example of file's content:


As can be seen from the table above, it is typical text file with data. I used two such files, but with different numerical data. I wanted to write some script that takes those to files, performs some mathematical operation on numerical data, and gives summary of calculation.

In this moment I'm not going to describe or explain further details attributed to this script, or give any example code. Just want to share my opinion about my first impression of Ruby.

First steps

I must say, that starting to learn Ruby, was quit easy. This is mainly because of book-like tutorials available at Ruby's homepage. I hadn't have any major difficulties in writing my script. However, there was one thing which caused a little of confusion at the start - iterators like in line (2):

myarray = [1,2,3,4] # (1) create array of name
myarray.each { |i| puts i} # (2) for each element in myarray do 'puts i'-print i

But, after a while, you can get used to them, and what's more important, see how useful they are.

There are many more other inventions in Ruby, which I will be describing as time goes.

Conclusion

In conclusion, I must say my program was written relatively fast. I didn't have any bigger problems with it. However, there was huge problem with making intersection of two arrays of objects, but my own solution to this obstacle, I will describe later. Despite this I must definitively say that I will continue to use Ruby, because it is very clean and easy language.

No comments:

Post a Comment