FEBRUARY ESCAPED. RECAP:: Best Valentine: Ruby on Rails

FEBRUARY ESCAPED. RECAP:: Best Valentine: Ruby on Rails

red-metallic-heart-valentines-day-ever-so-lovely-earrings1_large

I’ll start with Valentine’s Day – my first date with Ruby on Rails. It was fantastic. We spent five straight hours together on a romantic, blizzardy Saturday afternoon, snuggled in the cozy offices of Dev Bootcamp in the Financial District of NYC. I know it’s early to say this, but from first download to first project pushed to GitHub from my command line…I’m pretty sure it’s love.

Prior to starting the Ruby track in the Code Academy Labs curriculum I had dabbled in every language track aside from Ruby: HTML, CSS, JavaScript, jQuery, Python, and PHP. I’m not sure why I left Ruby for last, but I’m glad that I did. Now I can appreciate Ruby’s elegance.

According to www.ruby-lang.org, “Ruby is a dynamic, open source language with focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.” Ruby was designed and developed by Yukihiro Matsumoto (or “Matz”). Matz created Ruby because he wanted programming to be more enjoyable for the programmer. Ruby was designed to emphasize human needs over computer needs.  Apparently, at a Google Tech Talk in 2008, Matsumoto explained that Ruby is designed to make you fall in love =>

I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language.” – Yukihiro Matsumoto | Google Tech Talks, 2008

images

If you’ve ever read any Ruby code, you’ll notice that unlike JavaScript (not to hate), it reads a lot like plain english.

For example…

A JavaScript function generally looks something like this:

var name = function(param1, param2) {

           if (param1 === param2) {

                // executes this code if condition is true!;

           } else {

            // executes this code if condition is false!;

       }

};

In Ruby, the same function generally looks like this:

def name (param1, param2)

      if param 1 > param2

          puts “param1 is greater than param2”

     else

         puts “param2 is greater than param1”

     end

end

See how it’s a little easier? You don’t have to think so much about white space or semicolons in Ruby. In JavaScript, a forgotten or misplaced semicolon will stop your program from running. With Ruby, you will spend less time fixing bugs and more time focusing on the logic of your program.

Ruby is an object-oriented, high-level programming language. High Level programming languages read more like english and less like byte code (think 0101001 – matrix projections on the wall).  High level languages need to be interpreted or compiled into machine code before they can be understood by the computer. Machine code is a low-level language. Machine code is the only language that can be understood by a microprocessor directly without translation. You could code in machine code, but it would be much more complicated. You would need to remember a lot of different combinations of letters and numbers that have no obvious logic (08002FA 0G034FA … etc ).  Low-level languages have very little abstraction between the language and the computer’s instruction set architecture. Low-level languages are obviously more difficult and time-consuming, but they are faster and use less memory since you are basically speaking the same language as your computer (but with a slightly different dialect). However, we are humans, and we love abstractions – so thankfully there are high level languages like Ruby. High Level languages feel more like natural languages and are easier to write, read, and maintain. This graphic from webopedia.com is a nice visualization. Ruby would be at the top of the pyramid.

Credit: http://www.webopedia.com/TERM/H/high_level_language.html
Credit: http://www.webopedia.com/

Ruby is an object-oriented language. For many new programmers the significance of ‘object-oriented programming’ (OOP) is probably flying over your head – it was for me, until I looked it up. We probably won’t be doing anything but OOP because most languages commonly used to build web apps and mobile apps are object oriented. Java, Python, C++, VisualBasic .NET, and Ruby are all ‘OO’.

OOP empowers the human. OOP says logic should be concept driven. First identify concepts in your data and map out the relationships between them, then write your logic. Pre-OOP, programming was about writing logic to manipulate objects/data input, processes, and output. The hierarchy of focus was logic => object; bottom to top, trickle up.  Object Oriented Programming flips that priority over. OOP approaches programming object => logic; top to bottom; no trickling, just powerful organized systematic efficiency.  For example, if I’m using OOP to create an address book, I would focus on the relationships between my data and start categorizing it into “objects”. When I look at my data, I see that all my friends have a Name, Phone Number, and Address. At the highest level, I would need a Person Object that takes Name, Phone, Address.  I can then make a New Person Object, and my program will know that New Person Bob will have a Name, Phone Number, and Address. For more on why OOP makes sense, read this article.

RubyOnRails

I have completed several Ruby on Rails projects. You can see them here: www.github.com/carobinson. More to come.

< C >