Why I Love Ruby

If you’re looking for a comprehensive comparison of 15 programming languages based on decades of experience, this isn’t it. I’m a hobbiest programmer. Most of my “programs” are either in bash or Python, fit on one page, and are based firmly in laziness. But I do know beauty when I see it, and Ruby is beautiful.

In this post I’m going to show you, using just a points from the beginning of a Ruby book, why I love this language more than any other. I write this post because I’m always given “the look” by people when I tell them I’m learning Ruby. Most either think it’s:

not a “real” programming language (those are the C and Java people)

a lame replacement for Perl (Perl people)

a slightly different Python (people who don’t know either Python or Ruby)

This post is designed to counter that look.

Intuitiveness

To me, programming should be intuitive before anything else. You should be able to think about problems, start writing, and realize that you’ve solved some. Ruby isn’t there yet, but it’s the closest thing I’ve found. Check out this syntax:

string.length

That’s it. Prints out how big the string is. No biggie, but notice you don’t need any parenthesis. Very cool.

string.count('m')

Find that letter in the string, and print how many there are.

string.length.next

Utterly sick. Whatever the length of your string was, plus 1. Oh, and strings are completely mutable in Ruby. You can do useful things like this:

string.upcase

…which returns your string, but in all upercase. And here’s the cool bit: if you look at your string again it’s still lowercase. But if you want to permanently change it you can too:

string.upcase!

That’s it. Just add the exclamation point and you’ve permanently changed the string in place. Wicked. Ok, now check out these boolean checks:

string.empty?

This returns a true or false, based on whether or not the string is empty or not. Insane. Here’s another:

string.include('test')

Returns a true or false based on whether or not your string “includes” the string ‘test’. But you already knew that, and that’s the point. It’s SO DAMN easy to read and write. Check this out:

3.times

What do you think that does? It does whatever you tell it do — three times. W00t. I’m in love with this language.: