Why you need to learn Ruby and Rails

Official Ruby logo
Image via Wikipedia

With increasing visibility for the Ruby programming language, and the passion that people show for Ruby-on-Rails for web development, we felt that we would like to delve a little into what makes Ruby so cool and Rails so hot. Especially, in light of the fact that Ruby Fun Day is happening in Pune on Saturday, we wanted to give our readers a feel for why the should consider attending Ruby Fun Day. With that in mind, we invited Nick Adams of Entrip and SapnaSolutions (both those companies use Ruby-on-Rails as a cornerstone of their offerings), to tell us why Ruby and why Rails.

Ruby is an interpreted language like Python, Php, Perl, and a whole host of other popular Unix based languages. It was invented in 1992 by a Japanese man. However it only shot to fame in the last few years when the web development world started getting very excited about a new framework called ‘Ruby on Rails’, which arrived in 2005. But I’m getting ahead of myself. First, I’ll look at Ruby in its own right. Then, we’ll take a look at Rails and what’s cool about it.
The first thing you’ll notice about Ruby is it’s beautifully easy syntax:
5.times { print "Hello Pune!" } 
Goodbye to semi colons, variable declaration, etc it makes for readable code while ensuring you don’t spend more time than you need with coding. Ruby is 100% object oriented, in fact, everything in ruby including variables, are objects. That can be a little overwhelming at first, but it begins to make sense as you use a framework like rails and really reveals its true power when you want to change or add to the core ‘String’ class, on the fly. It means, in basic speak, that Ruby is very flexible. But there is more. Ruby has cool features like blocks, iterators, and a wealth of all the expected higher level language features like ‘capitalize’ and ‘reverse’ methods for strings.
Ruby on Rails
Image via Wikipedia

Rails is of course a web development framework. It is important not to see Rails as simply a collection of new classes and methods designed to aid web development. There are two things that I believe are important to understand before you dive into Rails. One is the MVC pattern of design. The MVC pattern of system design separates application logic into distinct parts making development fast, but also scalable and logical. The second is the rails conventions. Although sometimes ambiguous and debated, sticking to the basic rails conventions and understanding how the framework is designed to work will greatly aid collaboration, and futureproofing of your app.

What’s so cool about Rails? I recently interviewed someone who has worked in Java, Php and Rails for web development. I could sense the passion in him to work for a company that specialises in Rails, and didn’t need to explain why. If you have ever built a web application in .net, java, or php, you’ll really appreciate the power of Rails. It’s fast, modular, and working in Ruby is fun because you create clean, readable code. It’s free. Ajax and Web 2.0 style features are easy. Fully unit testing your app is easy. Roll out new ideas in weeks instead of months. Setup is easy, in any environment, but being open source it favours ‘nix based environments like Linux and Mac.
It all sounds great, doesn’t it? I would advise, however, that Rails is best understood by those who have understanding of the web and building database driven web applications already. Rails is a framework built on long standing notions, it’s not a magical new web development language. It makes what exists already, much easier and faster. Understand the Web. Understand Web Applications. Understand MVC. Then learn Rails, and you’ll never look back!

About the Author – Nick Adams

Nick Adams is the co-founder of Entrip, an integrated travel utility that gives a map-based interface to plan your trip, capture your experiences in multimedia, and share them with friends. SapnaSolutions is the Ruby on Rails Development company behind EnTrip. They make Web Apps for clients and develop in house products. He can be reached at nick [at] entrip [dot] com
Reblog this post [with Zemanta]

10 thoughts on “Why you need to learn Ruby and Rails

  1. Short and sweet. Will lure everyone into trying “Ruby on Rails”. Creating simple CRUD model in java or .net would take you some time, but in ROR it would take you seconds and add a minute to that for applying ‘Ajax’ to it.

  2. That was a very good write-up that crisply summarizes the beauty of Ruby and Rails.

    Nick concludes, “Understand the Web. Understand Web Applications. Understand MVC. Then learn Rails, and you’ll never look back!”

    I’ll however add “Learn Ruby” before “Learn Rails”. I’ve seen a good number of “Rails” programmers struggle after a point (when they wanna make their apps more than simple convention-supported CRUD apps) because they aren’t good “Ruby” programmers yet (and hence aren’t able to understand/leverage the Rails “magic”).

    I’ve written more with helpful suggestions for Ruby learners here (all drawn from personal experience): http://www.wikyblog.com/AmanKing/Learning_Ruby_and_Rails

  3. Depending on where you come from, the syntax 5.times… may appear either beautiful or plain weird. But whatever the initial impression, one starts appreciating it as the power unfolds. The syntax ‘5.times’ might look like something completely out of the blue at first glance, but once one recognizes that 5 (or any number for that matter) is a first-class object, things start falling in place. Try playing with this further using ‘irb’ (the ‘interactive ruby’ command-line tool which is a part of the ruby distribution) to explore the object ‘5’ further as follows: 5.class, 5.methods, 5.methods.sort [send message ‘methods’ to 5, which returns an ‘Array’ – further send a message ‘sort’ to this returned Array object if you like to see the methods ordered]. And if you haven’t guessed this already, do note that brackets to function calls are absolutely optional if the syntax is unambiguous (so, the above is equivalent to
    5.times(){puts “Hello Pune!”}
    which is equivalent to
    5.times(){puts(“Hello Pune!”)}
    What comes within the braces ({}) after ‘5.times’ is a _block_ – 5.times is by itself uninteresting, unless you can _do_ something 5 times, no? Blocks are a very powerful concept, which are defined at one place but executed elsewhere. They have access to the context where they are defined (closures). Use of blocks (and associated Proc objects) can lead to very
    interesting, succinct code!

    And again, if you are a C/C++ or a Java programmer feeling wary about jumping into something new and have that feeling of your uber-cool libraries not being accessible from Ruby (and hence a new learning curve apart from the heart-burn) – fear not! Ruby, being an interpreted language, runs in a VM of
    its own. The ‘official’ Ruby VM is C code, but obviously the cool thing that the JVM is, you can run Ruby inside the JVM too. And the Ruby VM developers have made sure that access to your favourite libraries is as easy as possible. Many have already made these libraries accessible via Ruby. I would term the Java VM as more powerful in this regard, giving you access to native libraries apart from all the Java goodies (look up ‘ruby+ffi’ on yahoo/google search).

    Then again, metaprogramming takes Ruby fun to newer heights. Rails wouldn’t have been (easily) possible had it not been for Ruby’s abilities in this regard. How would you feel if told that there are database access methods named (for eg) ‘find_by_name’ or ‘find_by_name_city’ that aren’t defined anywhere but still create appropriate SQL calls (‘where name = …’ or ‘where name = … and city = …’) because you can intercept ‘function undefined’ events, look at the function name and arguments, and create the right SQL on the fly? Or even before that, a class mapped to a database table ‘knows’ which table it is supposed to represent in an object form, just by looking at its *own* name? The good news is that all the cool libraries developed as part of the Rails initiative can be used in plain Ruby code without all the rails framework overhead too.

    Well, enough said for a comment. You’ve got to experience it to believe it!
    (PS: Not saying here that Ruby is unique – Python, for example, is cool too – but a Python-junkie would be a better marketeer for it 😉 )

Comments are closed.