Ruby on Rails 4 vs. .NET MVC 5 Smackdown – November 2013, YYC Ruby/.NET Meetup – Hosting



Ruby on Rails 4 vs. .NET MVC 5 Smackdown – November 2013, YYC Ruby/.NET Meetup – Hosting

0 0


smackdown

Presentation for November 2013 Ruby YYC Meetup

On Github benstevenson / smackdown

Ruby on Rails 4 vs. .NET MVC 5 Smackdown

November 2013, YYC Ruby/.NET Meetup

Ben Stevenson & Simon Timms/ @bennett_stevens @stimms

Fight!

  • Hosting
  • ORM
  • Cost
  • Performance
  • Editor Templating vs. Formtastic

Hosting

Where your app lives

  • Host it yourself
  • Platform as a Service(PaaS)
  • Infrastructure as a Service/Cloud hosting(IaaS)
This is important, there are so many ways one can choose to deploy production applications,

Roll your own

Get someone else to do it...

The "Monster" of Managed Hosting

The obvious and most popular example. Uses AWS and at some point we've (pretty sure) all used Heroku in some capacity.

The Deal

  • Platform as a Service(Paas)
  • Scalable
  • Addons
  • Quick easy setup
Expandable to whatever your needs are. More add-ons than you can shake a stick at! Redis, RabbitMQ, SendGrid, and 143 more listed on the site. Monitoring, media, payment, logging, caching. Pricing is high, for Ruby hosting... which is just shy of 3K a month for 20 2X web dynos and 20 2X workers. Approximate. But that's about normal when you compare against Windows Hosting at about 66% the cost of a comparable setup with Windows.

How easy?

Sure...

The Actual Steps

  • Sign up
  • Download and install the Heroku Toolbelt
  • > Forge:Projects bennett$ heroku login
    > Enter your Heroku credentials.
    > Email: the.benstevenson@gmail.com
    > Password (typing will be hidden): H4Ckz0r5
    > Authentication successful.
                    
    > Forge:Projects bennett$ heroku create windnoes
    > Forge:Projects bennett$ git push heroku master
                    

Or use... anything you can build...

The nice thing about Ruby is that there is most likely an implementation possible on any hosting provider in the known universe, often more than one.

Other methods for doing things

If you're not a sysadmin, because we're good, damn good, but not at everything. Offload the work to libraries to help manage your hoard of Linux VMs and keep the up to date, secure and configured the same. But the number of ways you can deploy applications in Ruby is astonishing and because of that you've probably never head of some of them.

In comparison

It took two hours, 3 restarts, countless dependencies, one really nice install screen to even get Visual Studio express installed and functional. Then dealing with the eye-gougingly magical IIS not wanting to connect outside of the VM, another hour to figure out git integration in Visual Studio Express, failing at that, and installing the Github Windows client instead. Oh and one forced install of IE 10. Yeah things worked great picking things up.

Active Record

Some things weren't possible (or at least easy in the past)

  • Cool to love/hate with AR
  • Too much magic
  • OMG horrible syntax! Burn it!
As a Rails developer, how much you love or hate AR is dependant on the age of your fixie.

It's OK

              
user = User.new(name:"Jane")
user.save!

User.where(name:"Jane").first
              
            

Simple, straight-forward, does it's job.

Model classes represent tables and instances are rows, 1:1.

Convention over Configuration

User(model) = users(table name)

User::Role(model) = user_roles(table name)

String inflections control how and

schema.rb

              rails g model user name:string
              rails g model family name:string
              
ActiveRecord::Schema.define(version: 20131120045647) do

  create_table "families", force: true do |t|
    t.string "name"
  end

  create_table "users", force: true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end

              
            

Create Migration

              rails g migration AddEmailAndFamilyToUsers email:string family:references
              
# db/migrate/20131120045647_add_email_and_family_to_users.rb
class AddEmailAndFamilyToUsers < ActiveRecord::Migration
  def change
    add_column :users, :email, :string
    add_reference :users, :family, index: true
  end
end
              
              rake db:migrate db:test:prepare
            

Result

              
ActiveRecord::Schema.define(version: 20131120045647) do

  create_table "families", force: true do |t|
    t.string "name"
  end

  create_table "users", force: true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "email"
    t.integer  "family_id"
  end

  add_index "users", ["family_id"], name: "index_users_on_family_id"

end

              
            

Arel

              
                users = Arel::Table.new(:users)
                query = users.where(users[:name].eq("Jane"))
                query.to_sql
              
              "SELECT FROM "users"  WHERE "users"."name" = 'Jane'"
            
Just like LINQ, without the GUI

Alternatives

Sequel is extremely close to Active Record in terms of syntax, however has been built with much more emphasis on performance. ROM is a new one but will be built much in the same manner as Datamapper was, which is essentially the same idea as Contexts in .NET EF. Where database interactions are managed through essentially object stores instead of object classes know how to connect and build/persist objects. Much like EF objects can be composed of differing data tables, Complex Types.

Performance

So there's this one little fact... MRI doesn't do multi-threading.

It doesn't matter!

  • More than 1 Ruby.
  • JRuby
  • Rubinius
There's MRI( Matz Ruby Interpreter), JRuby runs on the Java Virtual Machine, Rubinius is a reimplementation of Ruby supporting proper threading.

We've got options too!

All boils down to the same CLR

Where's the real cost in development?

  • Developers cost way more than hardware.
  • You can build applications quicker, more streamlined, no code behind assembly files.
  • If you're chops are up to the task, without leaving the same terminal.

Makes it easy to do the right thing

  • CDN Support built into framework
  • Turbolinks
  • Rails-API
  • Open platform, open tools.
Being open source opens the world with possibilities for what could be, not what is or what's coming next.

You can do anything you want in Rails

Cost

  • Free
  • Questions...?

Ok fine that was mildly loaded.

  • As free as you're willing to make it.
  • Swap and play.
  • Editors... my god the options.
    • Don't like VI? Use Emacs.
    • Don't like Emacs? Use Sublime or Text Mate
    • I need the IDE look! Use RubyMine

RubyMine

It's got everything, since the last time I tried it which was a couple years ago. RSpec, Minitest integration. Code completion as well as can be expected. Even RubyMotion support if you're doing a iOS application. When compared to Visual Studio, Windows, IIS hosting... actually I have no idea what the damn things cost for a single person. I've seen figures ranging from 500$ for a single Visual Studio license, and 250$ for a single Windows install. Does someone here know what they cost for a team? Probably not unless you're a sales rep for Microsoft. You can't even find the information on the site

What about server costs?

Linux = Cheaper

Every hosting service that I know of (exp. of AppHarbor) support Linux VM's, Linux is inherantly cheaper than Windows to build and maintain. On Azure it is ~66% the cost to host a Linux VM of decent performance.

With Windows

  • Would you like a GUI with that?
Ok fine, no one wants to remember clippy. But this illustrates a fundamental difference between the two frameworks. What can be accomplished with trivial text editing is ofuscated beneath a wash of windows and wizards. And when things go wrong.

JRuby

1 hour to port a medium sized application over while learning.

Huge performance increases without signifigant change to code-base.

Specs passing. The JVM is the biggest competitor to the CLR, and it can be used as a long-term evolution plan in Rails.

Editor Templating vs. Formtastic

On Rails

  • Stick with normal form helpers, they work.
              
<div class="field">
  <%= f.label :name %><br>
  <%= f.text_field :name %>
</div>
              
            

Options!

A (Contrived) Example!

Default implementation in .NET

                
  @Html.ValidationSummary(true)
  <div class="form-group">
      @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
      <div class="col-md-10">
          @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
          @Html.ValidationMessageFor(m => m.UserName)
      </div>
  </div>
                
              

Formtastic (w/ Bootstrap 3 Support)

                
  <%= f.semantic_errors %>
  <%= f.inputs do %>
    <%= f.input :username %>
  <% end %>
                
              

Surely a nightmare to configure

              
gem 'formtastic-bootstrap'

# config/initializers/formtastic.rb
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder

# app/assets/stylesheets/application.css
*= require formtastic-bootstrap
              
            

Formtastic: Once again options...

Or with Zurb Foundation

              gem 'formtastic-zurb-foundation'
            

Or with simple_form

              rails generate simple_form:install --bootstrap
            

Or with simple_form and Zurb

              rails generate simple_form:install --foundation
            

Or add in TopCoat

              gem 'topcoat-rails'
              
                # app/stylesheets/application.css
                *= require topcoat/desktop-dark
                *= require topcoat/desktop-light
                *= require topcoat/mobile-dark
                *= require topcoat/mobile-light