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

33
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer by Jon Kruger

Upload: jon-kruger

Post on 06-May-2015

1.221 views

Category:

Technology


8 download

DESCRIPTION

From CodeMash 2011

TRANSCRIPT

Page 1: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Venturing Into The Wild: A .NET Developer's

Experience As A Ruby Developer

by Jon Kruger

Page 2: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Email: [email protected]: @JonKrugerBlog: http://jonkruger.com/blog

Page 3: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

My Journey

Page 4: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

}

Page 5: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

ASP .NET MVC

Page 6: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Why Ruby?

Page 7: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Why Ruby?

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

-- Greg Malcolm

Page 8: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Why Ruby?

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

-- Leon Gersing

Page 9: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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() { ... }}

Page 10: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Why Ruby?

Page 11: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

How I Learned Ruby on Rails

Page 12: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

How I Learned Ruby on Rails

Page 13: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

What I’ve Learned

ASP .NET MVC and Rails are very similar

Page 14: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

What I’ve Learned

Learning the Ruby/UNIX way

Page 15: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

What I’ve Learned

You can do more with less code

Page 16: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 17: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 18: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 19: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 20: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 21: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 22: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

What I’ve Learned

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

Page 23: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

What I’ve Learned

Innovation is everywhere

Page 24: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

What I’ve Learned

Patterns and “best practices” are different between static and

dynamic languages

Page 25: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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?

Page 26: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

The Active Record Pattern - Ruby

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

Page 27: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 28: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Code!

Page 29: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Conclusions

Page 30: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

Rails in the Enterprise

Twitter Github

Hulu Groupon

Page 31: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

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

Page 32: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

ResourcesRuby Koans

http://rubykoans.comRailscasts

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

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

Page 33: Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer

My InfoEmail: [email protected]: @JonKrugerBlog: http://jonkruger.com/blog