Saturday, September 1, 2012

My love affair with Ruby on Rails

I was never big on coding.

My undergrad degree was in Computer Network and Information Systems, and about 25-30% of our curriculum focused on writing code and application development. And I hated most of it.

I was always more interested in The Big Picture; how to make code do cool stuff, and how that cool stuff can make people's lives better, or solve their problems. The problem with this approach of course is that, to get to the 'solve a problem' strata of Product Development, you need to master each of the lesser strata:

  • What language will you use? 
  • What is the syntax of that language? How do you define a method in that language?
  • How does the language organize it's data?
Each of the above points abstracts into the one that follows it, and at any given step, the choice you've made may prove to be the wrong one based on your needs. It can get ugly, and I never liked it. Give me a tool that Just Works, and let me focus on designing a killer UI/UX.

At some point, language developers started to get the hint: the emphasis now is no longer on PHP vs. Perl (or tcl, which is why Zipcar is screwed, by the way), but on how you can make these languages dance. And in order to make languages dance, you need frameworks.

Frameworks basically abstract the actual writing of code into APIs and objects which, from the app developers standpoint, are black boxes: I don't care how you capture a user's name and e-mail address, just that you capture it.

There are lots of different kinds of frameworks out there, but because this is 2012, and nobody is making apps for your desktop anymore (unless you use a Mac, more on that later), for the time being I am going to use the word 'framework' to mean 'web application framework.' In other words,  an app that 'lives' in the cloud (as opposed to on your desktop).

There are a couple of pretty solid frameworks out there that are based on popular programming languages with robust documentation and user communities: Django (Python), Joomla (PHP), Struts (Java). One that's recently been making waves in the application development community is Clojure, which is based on LISP of all languages.

But the framework that's changing the world is Ruby on Rails. And I'm in love with it.

What is Ruby on Rails (hereafter referred to simply as 'Rails')? Let's break it down.

Ruby is a scripting language, like Python and Perl- no more, no less. You can write a Ruby script to create backups on your files, rename a bunch of directories, or send you an e-mail every time a file on your computer changes.

What sets Ruby apart from its contemporaries is its distinctly 'human' design. It is designed to a) make writing code easy, painless, and most importantly, not surprising, and b) the emphasis it places on the developer instead of the machine.

Rails is the most popular framework for Ruby. Rails is written in Ruby (duh), but what it also does that very few web frameworks before it is place an emphasis on translating your ideas into code for you.

If you have Ruby on Rails installed, here's how you create an application:

rails new myApplication

That's it. One command, and you just created an application that will run. Granted, it's an application that won't do anything, but that one command created somewhere on the order of 10 directories and 50 files that you would otherwise have to create yourself. As someone who does not pine to write code, but would rather spend his time designing and architecting the application, this is like manna from heaven.

Ruby on Rails makes it ridiculously easy to create a solid web app and worry about the other stuff later. This is valuable to businesses because they can get a few generalists and have a good-enough app up and running in no time. Then, if/when it starts to outgrow the outsourced cloud model, hire a sysadmin to maintain the infrastructure. As your business scales, you can scale your workforce. Ruby on Rails makes it easy to add a layer of abstraction to parts of your web app so that when the time comes to take control of all that Other Stuff, you don't need to completely re-architect your product: just update a view lines of code, bounce your server, and you're done.

Rails as a framework embraces a philosophy called 'Convention over Configuration,' which is evident in the command above. Rails assumes that your app (and the files that make it up) will be arranged and accessed in a certain way, and leaves you to change it if you need to structure your app differently

This Convention over Configuration paradigm is also evident in the rails generate command. This is where the real power of Rails lies. Rails embraces an architecture called Model/View/Controller, meaning the app is split into three key components: data (model), UI (view), and business logic (controller). Rails allows you to build all three of these with minimal effort using the generate command.

rails generate model user will create all the files necessary to create a model for your users. You can even specify what data you want to collect about your users when you invoke the command:

rails generate model user id:integer firstname:string lastname:string

I'll probably be writing more about Ruby on Rails as I work on my app prototype, StormCloud, but for now, here's some further reading:

Git/GitHub: Git is a lightweight and fast version control system that Ruby is designed to integrate tightly with. GitHub is a free public hosting site for Git repositories.  
Heroku: Heroku offers free hosting for web apps, and Rails apps in particular. Heroku makes it ridiculously easy to deploy apps and prototypes to Production, which if you're looking to build a business, is both crucial and unbelievably valuable to businesses.






















2 comments:

  1. Oh snap this something I have been hoping for someone to invent for a long time. I understand logic and the gist of programming but do not have the time or motivation to lock myself in a room and learn syntax. A very hearty thanks to you for sharing this with us Mr. Rubin.

    ReplyDelete
    Replies
    1. Dave,

      If your interest is piqued. here's a free tutorial on how to get running on Rails- everything you need to create, build, and host your own web app is completely free, from GitHub to Heroku, and the guide makes it easy and painless. This is the same guide I used when building StormCloud:

      http://ruby.railstutorial.org/

      Delete