venturing into the wild: a .net developer's experience as a ruby developer

Post on 06-May-2015

1.221 Views

Category:

Technology

8 Downloads

Preview:

Click to see full reader

DESCRIPTION

From CodeMash 2011

TRANSCRIPT

Venturing Into The Wild: A .NET Developer's

Experience As A Ruby Developer

by Jon Kruger

About MeIndependent consultant in Columbus, OH.NET, Ruby on Rails, Agile

Email: jon@jonkruger.comTwitter: @JonKrugerBlog: http://jonkruger.com/blog

My Journey

ASP .NET WebFormspublic void Page_Load(Object sender, EventArgs e){

}

ASP .NET MVC

Why Ruby?

Why Ruby?

“Sometimes I want to do Ruby because it means that I’m more likely to be able to do TDD.”

-- Greg Malcolm

Why Ruby?

“I feel like the shackles have been taken off.”

-- Leon Gersing

Why Ruby?public interface IGetObjectService<T> where T : EntityBase{ public T Get(int id); public IList<T> GetAll();}

public class GetObjectService<T> : IGetObjectService<T>{ public GetObjectService(IRepository<T> repository) { }

public T Get(int id) { ... } public IList<T> GetAll() { ... }}

Why Ruby?

How I Learned Ruby on Rails

How I Learned Ruby on Rails

What I’ve Learned

ASP .NET MVC and Rails are very similar

What I’ve Learned

Learning the Ruby/UNIX way

What I’ve Learned

You can do more with less code

Doing more with lesscreate table Users(    id int,    name varchar(100),    user_status_id int,    created_at datetime,    updated_at datetime)

class User < ActiveRecord::Base  belongs_to :user_status  has_many :roles, :through => :user_roles  validates_length_of :name, :maximum => 100  named_scope :active, :conditions => ["user_status.id = ?", UserStatus::ACTIVE]end

Doing more with lesscreate table Users(    id int,    name varchar(100),    user_status_id int,    created_at datetime,    updated_at datetime)

class User < ActiveRecord::Base  belongs_to :user_status  has_many :roles, :through => :user_roles  validates_length_of :name, :maximum => 100  named_scope :active, :conditions => ["user_status.id = ?", UserStatus::ACTIVE]end

Doing more with lesscreate table Users(    id int,    name varchar(100),    user_status_id int,    created_at datetime,    updated_at datetime)

class User < ActiveRecord::Base  belongs_to :user_status  has_many :roles, :through => :user_roles  validates_length_of :name, :maximum => 100  named_scope :active, :conditions => ["user_status.id = ?", UserStatus::ACTIVE]end

Doing more with lesscreate table Users(    id int,    name varchar(100),    user_status_id int,    created_at datetime,    updated_at datetime)

class User < ActiveRecord::Base  belongs_to :user_status  has_many :roles, :through => :user_roles  validates_length_of :name, :maximum => 100  named_scope :active, :conditions => ["user_status.id = ?", UserStatus::ACTIVE]end

Doing more with lesscreate table Users(    id int,    name varchar(100),    user_status_id int,    created_at datetime,    updated_at datetime)

class User < ActiveRecord::Base  belongs_to :user_status  has_many :roles, :through => :user_roles  validates_length_of :name, :maximum => 100  named_scope :active, :conditions => ["user_status.id = ?", UserStatus::ACTIVE]end

Doing more with lesscreate table Users(    id int,    name varchar(100),    user_status_id int,    created_at datetime,    updated_at datetime)

class User < ActiveRecord::Base  belongs_to :user_status  has_many :roles, :through => :user_roles  validates_length_of :name, :maximum => 100  named_scope :active, :conditions => ["user_status.id = ?", UserStatus::ACTIVE]end

What I’ve Learned

If it’s hard, you’re probably doing it wrong

What I’ve Learned

Innovation is everywhere

What I’ve Learned

Patterns and “best practices” are different between static and

dynamic languages

The Active Record Pattern - .NET

public class Employee{

public static Employee Load(int id) { ... }public bool Save() { ... }public bool Delete() { ... }

}

How do I stub out the Load method in a test?How can I implement cross-cutting concerns (e.g. caching when saving) without duplicating code?

The Active Record Pattern - Ruby

In Ruby, I can stub out class methods (i.e. static methods)

The Active Record Pattern - Ruby

class Employee < ActiveRecord::Base include Cacheableend

module Cacheable def save Cache.save(self) super end

end

In Ruby, I can mix in modules that will modify the class

Code!

Conclusions

Rails in the Enterprise

Twitter Github

Hulu Groupon

Resources - BooksRails for .NET Developers

by Jeff Cohen and Brian EngAgile Web Development With Rails

by Sam Ruby, Dave Thomas, David Heinemeier Hansson

Programming Ruby 1.9 (aka the “Pickaxe” book)

by Dave Thomas, with Chad Fowler and Andy Hunt

All found at http://pragprog.com

ResourcesRuby Koans

http://rubykoans.comRailscasts

http://railscasts.comWhy’s Poignant Guide To Ruby

http://mislav.uniqpath.com/poignant-guide/

My InfoEmail: jon@jonkruger.comTwitter: @JonKrugerBlog: http://jonkruger.com/blog

top related