6 reasons why you should try Ruby

I love Ruby. I first learned about it on the Internet several months ago and decided I wanted to give it a try. I was intrigued by the kind of buzz around it. I felt that the Ruby crowd was smaller than the PHP, C# or even python crowd, but those who liked Ruby seemed to like it A LOT. I went to the ruby website and decided to try the online tutorial. At this moment, I just knew this thing was for me. I didn’t know exactly why at the time, but I knew that this language would become my language, my little favorite. Ruby would become the language I would defend proudly in a geek crowd wearing my transformers pajama.

So here we go with another “top ten” kind of post that is so popular on the blogosphere these days : 6 reasons why you should try ruby

1) Enjoy the power of code blocks!

Code blocks are chunks of code that can be passed to any ruby function. They take the form of anonymous functions and can be used to achieve a lot of useful things. One of the main use of ruby code blocks is to achieve what we could call “intelligent loops”. Instead of managing the internals of the loop yourself, you delegate the work to some object method, passing it a code block that will have to be executed at every passages in the loop. The method will have to make use of the yield keyword in order to call the block that has been passed to it. I wrote an article about code blocks in case you would like to know in more depth what I think of them.

2) Writing conditionals never been that exciting

What is more boring than writing a traditional if-then-else condition? Well, a lot of things in fact. But writing a “if” is still boring… a little… I think. In Ruby, you can decide to put the conditional keyword either before or AFTER the tested expression. It may seems like useless, but I personally think it helps to improve the code clarity in some situations.

For example, instead of writing a statement like this :

You could also write :

I love it. But wait there is more! Everyone knows about the if keyword, but not everyone knows about the unless keyword. It’s pretty straightforward so I’ll just write an example and you’ll understand.

I personally like this last use of the unless keyword. In this particular case, I really wanted to put the emphasis on the idiotic dance while not bothering too much about the insignificant exception that follows. It all depends of the situation. Sometimes, the thing to do deserves more attention and some other times it’s the condition that matters the most. It’s only a question of personal taste, but it’s a nice touch nonetheless.

Note that there are other keywords you can place before and after the tested expression, like until and while.

3) You know you are addicted to OOP

With Ruby, everything is wrapped into objects, not only complex structures but native types as well. For example, String is not a keyword, it is the name of a ruby class. String contains methods that manipulates the internal string value. So instead of writing something like Uppercase(“blablabla”), you will write “blablabla”.capitalize. Instead of writing round(a_number) you will write a_number.round(). In short, there are less global keywords and more encapsulated methods. If you love OOP, I don’t have to convince you, I’m sure you’re already turned on.

4) Adopt a dynamic language today

Dynamic typing is wonderful and really should be taken seriously. You waste a lot of time declaring and giving a type to each of your variables in your statically typed language. Why not let an interpreter decides what kind of variable x really is only when you start putting some kind of value in it? It’s silly to say that dynamically typed languages are less serious than statically ones. When a programmer decides to create a variable in ruby, python or PHP, he will use it the proper way. He won’t put a number in variable x and later try to retrieves a date from it. Also, declaring variables takes more place in your code as well as more time in your life… and it’s just boring. Call me a hippie if you want, but I prefer a language that slacks off on types a little rather than one who points a gun at my head forcing me to code a certain way and trying to control everything.

5) Be part of a more underground community

Ruby isn’t the most popular language and shouldn’t be. Sure, It’s popularity is growing a lot recently and that is a great thing, i don’t say otherwise… but too much popularity and Ruby would lose some of it’s appeal. It’s just a special feeling to be part of a community that is a bit smaller and more underground. Small communities = more devoted people.

6) Rails

I just couldn’t pass aside Ruby’s best friend. When Rails arrived and revolutionized the web community, Ruby finally started to get some of it’s well deserved credit. Developing a web application with Rails is extremely fun and fast… and I’m not saying fast in the bad sense of the word. With Rails, you code less and you code better. Thanks in part to the MVC architecture but also to the greatness of the language hiding behind the powerful framework. Ruby and Rails forms a devastating combination. Ruby and rails convinced me that programming could be fun again… something I didn’t have anymore when I was developing in .NET (Yaaaaaaaaawn!).

There are tons of other reasons to try ruby. Could you give me a few?

  • el raichu

    don’t forget the rescue modifier

    some_hash = find_hash( parameter ) rescue find_hash( parameter, more_info ) rescue Hash.new

  • http://www.rubyfleebie.com Frank

    Excellent!

    You know what, I never thought using the rescue keyword this way. Thanks for the input.

  • Al

    Comment on #4:
    4) Adopt a dynamic language today

    While it’s true that dynamic typing allows you to accomplish more with less code, you will inevitably run into more run-time vs. compile-time exceptions. Speaking from experience, the addition of strongly typed collections in Java 1.5 has resulted in far fewer bugs in my code, at the cost of additional tedious typing. My advice would be to ensure that you get complete code coverage with your unit test cases, and make sure you pass lots of random inputs into your class methods to test for unusual casting behavior.

  • Ze’ev

    Nice list.
    I would also recommend looking at Python & Django.