5 Things That ASP.NET Developers Would Love about Ruby on Rails

NetToRails

I’m a longtime ASP.NET developer, and indeed that’s how I’ve made my professional living for many years now, but I have to say there is a lot to love about Ruby on Rails.
There’s a simplicity and common sense approach that I really like.

I think other ASP.NET developers would enjoy certain aspects of Rails as well, so I put together a list of my 5 favorite things (in no particular order):

1) Migrations

If you’re like me, you really don’t like writing database change scripts in SQL. Wouldn’t it be nice if you could write the scripts in your favorite programming language rather than resorting to T-SQL? Well, with rails migrations you can!

You write your schema changes as a ruby class (or even generate them) and run it at the database to modify your schema. For example, to create a posts table, on the command line just type:

$ script/generate model Post name:string content:text

This will automatically generate the required class for you which looks like this:

class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.string :name
      t.string :title
      t.text :content

      t.timestamps
    end
  end

  def self.down
    drop_table :posts
  end
end

Then you just run “rake db:migrate” at the command line and your table is created. The framework even keeps track of which migrations have been run and versions them all so you can roll back to previous DB versions at any time.

2) Active Record

I love how active record does not force you to model out all your fields as properties. You simply build your table with migrations and then create a class of the same name that derives from ActiveRecord and Rails figures out the rest. No config files to set up or angle brackets to mess with.

It adds all the properties based on the table columns and a bunch of helper methods for finding records and working with the dataset, but your code is as simple as this:

class Post < ActiveRecord::Base
end

3) Opinionated

With Rails a lot of decisions are made for you and that’s a good thing! Instead of endlessly debating which of the 10 ORMs to use for your data layer, you just use Active Record because that’s what’s built-in out of the box and works for 90% of the cases.

Rails has a specific way of doing things, and if you buy into it, you can let the framework take care of a lot of the little details for you.

4) Lightweight

There’s something wonderful about not having to fire up a huge IDE to do development. Just launch your favorite text editor and start writing code. My personal preference for writing Rails code on windows is the E-TextEditor (which is modeled after TextMate), but I could just as easily use notepad++. 

This simply would not be possible with ASP.NET as there are just too many frameworks and libraries to deal with as well as just a lot of code to write that you almost need the IDE’s help to sort them all out. Not to mention, you need the IDE to compile your code (or the cmd line with hundreds of switches) which is not necessary in the the interpreted world of Ruby. The code and run cycle is almost instantaneous.

5) Less Code

After porting an ASP.NET MVC app to rails I was amazed with how little code it took in rails. The rails version was only about 25% of the code that was required for the ASP.NET MVC version.So, how is that possible?

Much of this is due to Active Record and the fact that I didn’t have to write any DB connector code, but also Ruby’s terse syntax and lack of strong typing just means that the amount of code you write is much less.

For example, a typical controller method in Rails looks like this:

  def show 
     @post = Post.find(params[:post_id])
  end

And then @post is automatically visible in the corresponding view. Nice and elegant – the way coding should be.

6 Comments » for 5 Things That ASP.NET Developers Would Love about Ruby on Rails
  1. bferman says:

    The Entity Framework provides similar functionality as Active Record and takes a lot of work out of writing data centric apps. EF can do both model first and code first, so take your pick.

    Even SQL Express Management Studio will generate stored procs for you that will drop old tables and recreate it them with your latest schema.

    Visual Studio provides (among so many other great things) that wonderful intellisense and immediately lets me know if I’ve made a mistake when I misspell a type name I intend to use.

    Strongly typed views and the speed of compiled code are nice bonuses too.

  2. Bryant says:

    To be clear, I’m not saying that the MS development model is bad. My only point was that there are some really fun things in the Rails framework that an ASP.NET developer would enjoy. In my mind, Rails is a good fit for public site or a startup and ASP.NET is a better fit for large corporate (LOB) apps.

    As for Entity Framework, it does beat Active Record in terms of complex domain mapping which can’t easily be done in AR, but that is overkill for 90% of sites. And getting going in EF is a much steeper set-up and learning curve then AR.

  3. Damien White says:

    Great post, all the things I love about Rails. I’m a .NET guy, and started using Rails a little while ago (actually I wrote a blog post as well http://blogs.visoftinc.com/archive/2010/03/25/my-affair-with-ruby-on-rails.aspx).

    I love Rails simplicity. I love migrations, and I love ActiveRecord. Using EF for my day job, I have a solid understanding of the good and bad of it. Things just aren’t nearly as quick using the MVC/EF stack.

  4. Bryant says:

    I totally agree with you Damien! There’s a lot I still like about .NET, but rails is so quick and simple to build a site that it’s addicting.

    I’ll check out your post. Glad to see someone on the same page!

  5. AdamMoon says:

    I believed it was going to be some tedious old publish, but it really paid for time. I will publish a weblink to this web page on my weblog. I am sure my guests will discover that very useful.

  6. This is very informative post.More and more of our new projects are custom solutions requiring a novel database structure to support a creative new business model. In most cases, Rails is an ideal way to realize build these solutions at a fraction of the usual time and expense.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>