Friday, August 05, 2005

Ruby: Programmer's Best Friend

I still cant remember how i got initiated into Ruby, but it definitely was a perfect example of serendipity! I do remember though, downloading and reading Programming Ruby aka the "The PickAxe" by Dave Thomas et al, and i was BLOWN AWAY!

Ruby is an Open Source Object Oriented programming/scripting language created by Yukihiro Matsumoto, a.k.a. “Matz” from Japan. In the foreward to the book, he writes -

"Man is driven to create; I know I really love to create things. And while I’m not good at painting, drawing, or music, I can write software.

Shortly after I was introduced to computers, I became interested in programming languages. I believed that an ideal programming languagemust be attainable, and I wanted to be the designer of it. Later, after gaining some experience, I realized that this kind of ideal, all-purpose language might be more difficult than I had thought. But I was still hoping to design a language that would work for most of the jobs I did everyday. That was my dream as a student.

Years later I talked with colleagues about scripting languages, their power and possibility. As an object-oriented fan for more than fifteen years, it seemed to me that OO programming was very suitable for scripting too. I did some research on the ’net for a while, but the candidates I found, Perl and Python, were not exactly what I was looking for. I wanted a language more powerful than Perl and more object-oriented than Python.

Then, I remembered my old dream and decided to design my own language. At first I was just toying around with it at work. But gradually it grew to be a tool good enough to replace Perl. I named it Ruby—after the precious red stone—and released it to the public in 1995.
Since then a lot of people have become interested in Ruby. Believe it or not, Ruby is actually more popular than Python in Japan right now. I hope that eventually it will be just as well received all over the world.

I believe that the purpose of life is, at least in part, to be happy. Based on this belief, Ruby is designed to make programming not only easy but also fun. It allows you to concentrate on the creative side of programming, with less stress. If you don’t believe me, read this book and try Ruby. I’m sure you’ll find out for yourself."

Ruby does all that Matz said it would and more! n lil wonder then, that its more popular than Python in Japan. The only surprising thing is why it hasnt caught on all over the pretty sure it will. Any good programmer needs to just work with Ruby for a few days and realise why its sooo much better than most of the other programming languages!

I told Hrishikesh ("thite" as we more commonly call him) bout Ruby and he too was HOOKED. Gautam (aka "geek") meawhile was learning Python.

So what is it that makes Ruby so gr8? Dave Thomas, in the preface of the book says -

"When Andy and I wrote the first edition, we had to explain the background and appeal of Ruby. Among other things, we wrote “When we discovered Ruby, we realized that we’d found what we’d been looking for. More than any other language with which we have worked, Ruby stays out of your way. You can concentrate on solving the problem at hand, instead of struggling with compiler and language issues. That’s how it can help you become a better programmer: by giving you the chance to spend your time creating solutions for your users, not for the compiler.”"

Having used Ruby for quite some time now, i havta agree. Whenever im writing code in Ruby, most of the thinking has gone into how to solve the problem rather than being stuck with the deficiencies of the language and how to get around them!

Ruby is a dynamically typed language (more on this in a later blog). Coming from a background of statically typed languages like C, C++, Java, etc. dynamic typing is soo beautiful, i wonder why ALL languages dont have it! Dave Thomas et al call it "Duck Typing" and say -

"In Ruby, the class is never (OK, almost never) the type. Instead, the type of an object is defined more by what that object can do. In Ruby, we call this duck typing. If an object walks like a duck and talks like a duck, then the interpreter is happy to treat it as if it were a duck."

Love that last line! :d

Well, i found duck typing pretty awesome as besides other advantages, it really helps incremental code development.

Another awesome resource for Ruby is Why's (Poignant) Guide to Ruby. Not only is it a fascinating read and a good source to learn Ruby, it also provides a unique take on Ruby. Read it to know more!

I hope those of you who read this blog feel tempted to give Ruby a try! Trust me itll change the way you code! Various downloads, source code, documentation, etc is available at the Ruby Home Page

Well, i think i should wind up this blog now! Examples of Ruby code and solutions to the Python Challenge in Ruby to follow shortly. Ill end by once again quoting Matz -

"The stone has started rolling. It will became a great mountain and fill the whole earth."
Yukihiro Matsumoto, a.k.a. “Matz”
Japan, August 2004
Preface to the Second Edition of "The PickAxe"


At August 05, 2005 9:19 AM, Blogger Nadeem Mohsin said...

Ok, I'm sold. As soon as I get enough time, I'm learning Ruby. Thite has been pakaving me for ages, coz I learnt Python last year, and never bothered to look up Ruby. My loss - I had time back then...

Dynamic typing is definitely the way to go, but I'm used to the Python version of it...'duck typing' sounds like an interesting idea though...

You might wanna throw in some code snippets - I know most people can get Python code simply by looking(I'm told that in that respect it beats even Ruby hands down) - I don't know about Ruby, so why don't you give it a whirl?

And btw, I don't know how far along you are in the Python Challenge, but you're going to hit a point around level 6 or 7 where Ruby probably won't help you - there's a special Python module involved. I stopped at level 8 when 6th sem exams rudely interrupted, and haven't gone back yet...That's another item on my To-Do list...

If you're serious about every aspect of programming languages, how about a post on INTERCAL? Google it if you don't know the name...

At August 05, 2005 9:21 AM, Blogger Nadeem Mohsin said...

Almost forgot - how about a post on Rails? Thite's explanation wasn't very illuminating...

At August 05, 2005 11:08 AM, Blogger Hrishikesh said...

I hate myself for this. I want to do all this and more, but where is the time?

Well, Nadeem, trust me, Ruby spoils everyone.

At August 15, 2005 12:48 PM, Anonymous Ayush said...

Three words: Ruby on Rails.

At August 22, 2005 2:31 PM, Blogger rajeev chhajer said...

hi guys,

ive been trying to learn something from this blog of yours..I see not much of changes..pls could u put up more material so that it would be useful.



Post a Comment

<< Home