From .NET to Rails,A Developers Story
Who the f**k is         Colin Gemmell.NET Dev for 3.5 yearsWebforms, MVC, UmbracoBig on ALT.NET idealsMoved to Ruby on Rai...
Why Ruby and RailsCheaper than developing with .NETArguably faster and more productiveEasier to test your codeOpen and fre...
Why Ruby and RailsThis man pays me to.      @chrisvmcd
.NET Development Environment     Window XP/Vista/7     Visual Studio 20XX     Resharper or Code Rush
My First RubyDevelopment Environment Window XP/Vista/7 Rubymine Cygwin Ruby Gems Interactive Ruby Console (irb)
Windows ProblemsRails traditionally deployed on Linux OSGem’s often use Linux kernal methodsor Linux LibrariesEngineyard i...
Development Environment  VMware workstation   Ubuntu   Rubymine   VIM + a lot of plugins   Ruby Gems   Interactive Ruby Co...
Development Environment   Find what is right for you.
RubyRuby Koans (http://rubykoans.com/)
Ruby and SOLIDSingle responsibilityOpen/ClosedLiskov SubstitutionInterface SegregationDependency Injection
Ruby and loose couplingIn .NET we use Interface and Dependency  Injection to achieve loose couplingRuby is loosely coupled...
Ruby and Monkey Patching
Add New Functionality to Ruby"Developer Developer Developer is awesome".second_wordNoMethodError: undefined method `second...
Changing implementation class ZombieKiller   def kill      self.shotgun.fire   end end zombie_killer = ZombieKiller.new pu...
Are you scared yet?If the idea of monkey patching scares you a   little, it probably should. Can you imagine   debugging c...
Testing Ruby and Rails
Testing Ruby and RailsTesting ensures code behaves correctlyTests ensure code compilesDebugging support patchy at bestIts ...
How I Tested .NET[TestFixture]                                           public class ZombieKiller : IZombieKiller {public...
Example RSpec testdescribe "when killing a zombie" do             class ZombieKiller  class Zombie                        ...
Range of TestingIn .NET there are a lot of test frameworksRuby test frameworks include TestUnit, RSpec,  Shoulda and Cucum...
The Rails WayOne project layout and only one layoutPrinciple of least surpriseChange it at your own riskHeavily based on c...
The Curse of Active RecordMakes really fast to get going with projectThe number one reason for slow apps (IMHO)Is to easy ...
The Curse of Active Record1 class Session < ActiveRecord::Base        19 module SessionModel2    # name > string          ...
The Curse of Active Recordclass Session < ActiveRecord::Base          module SessionModel # name > string                 ...
.NET Deployment.NET deployment predominantly through FTP or  copy to file shareBut what about databases, migrations, queue...
Ruby DeploymentDeployment is a solved problem in RailsBuilt on several partsDatabase migration come out of the boxBundler ...
DeploymentShock horror its a demo
From .NET to Rails,      A Developers StoryAny Questions?E-mail: pythonandchips@gmail.comBlog: pythonandchips.netTwitter: ...
Rails Scaling
Scaling RailsJohn Adams, Twitter operations     http://tinyurl.com/6j4mqqb
Upcoming SlideShare
Loading in...5
×

From dot net_to_rails

11,345

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
11,345
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

From dot net_to_rails

  1. 1. From .NET to Rails,A Developers Story
  2. 2. Who the f**k is Colin Gemmell.NET Dev for 3.5 yearsWebforms, MVC, UmbracoBig on ALT.NET idealsMoved to Ruby on Rails in May 2010Started the Glasgow Ruby User Group in March 2011
  3. 3. Why Ruby and RailsCheaper than developing with .NETArguably faster and more productiveEasier to test your codeOpen and free development
  4. 4. Why Ruby and RailsThis man pays me to. @chrisvmcd
  5. 5. .NET Development Environment Window XP/Vista/7 Visual Studio 20XX Resharper or Code Rush
  6. 6. My First RubyDevelopment Environment Window XP/Vista/7 Rubymine Cygwin Ruby Gems Interactive Ruby Console (irb)
  7. 7. Windows ProblemsRails traditionally deployed on Linux OSGem’s often use Linux kernal methodsor Linux LibrariesEngineyard investing on Rails development with windows
  8. 8. Development Environment VMware workstation Ubuntu Rubymine VIM + a lot of plugins Ruby Gems Interactive Ruby Console (irb)
  9. 9. Development Environment Find what is right for you.
  10. 10. RubyRuby Koans (http://rubykoans.com/)
  11. 11. Ruby and SOLIDSingle responsibilityOpen/ClosedLiskov SubstitutionInterface SegregationDependency Injection
  12. 12. Ruby and loose couplingIn .NET we use Interface and Dependency Injection to achieve loose couplingRuby is loosely coupled by design.Everything and anything can be changed.Thanks to being a dynamic language and……
  13. 13. Ruby and Monkey Patching
  14. 14. Add New Functionality to Ruby"Developer Developer Developer is awesome".second_wordNoMethodError: undefined method `second_word for "developer developer developer":Stringclass String def second_work return self.split( )[1] endend"Developer Developer Developer is awesome".second_word=== “Developer” Extension methods anyone?
  15. 15. Changing implementation class ZombieKiller def kill self.shotgun.fire end end zombie_killer = ZombieKiller.new puts(zombie_killer.kill) === Zombie head explodes class ZombieKiller def kill self.axe.throw end end zombie_killer = ZombieKiller.new puts(zombie_killer.kill) === Zombie Falls off
  16. 16. Are you scared yet?If the idea of monkey patching scares you a little, it probably should. Can you imagine debugging code where the String class had subtly different behaviours from the String youve learned to use? Monkey patching can be incredibly dangerous in the wrong hands. Jeff Atwoodhttp://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html
  17. 17. Testing Ruby and Rails
  18. 18. Testing Ruby and RailsTesting ensures code behaves correctlyTests ensure code compilesDebugging support patchy at bestIts all right, testing is a lot simpler
  19. 19. How I Tested .NET[TestFixture] public class ZombieKiller : IZombieKiller {public class ZombieKillerTest : SpecificationBase{ private IZombieKillerRepository _repo; private ZombieKiller zombieKiller; public ZombieKiller( private Zombie zombie; IZombieKillerRepository repo){ _repo = repo; } public override void Given(){ var repo = Mock<IZombieKillerRepository>(); public void Kill(Zombie zombie){ zombie = new Zombie(Strength.Week, zombie.status = "decapitated“; Speed.Fast); repo.UpdateZombie(zombie); zombieKiller = new ZombieKiller(repo); } repo.stub(x => x.UpdateZombie).returns(true); } zombieKiller.weapon = Weapon.Axe; } public override void When(){ zombieKiller.kill(zombie); } [Test] public void should_depacite_zombie(){ zombie.status.should_eqaul("decapitated"); }}
  20. 20. Example RSpec testdescribe "when killing a zombie" do class ZombieKiller class Zombie def kill zombie def save zombie.attack_with self.weapon true end end End end class Zombie < ActiveRecord::Base before do def attack_with weapon @zombie = Zombie.new( #do some logic to see #what happened to zombie :strength => :week, :speed => :fast) self.save @zombie_killer = ZombieKiller.new( end :weapon => :axe) end @zombie_killer.kill(@zombie) end it "should be decapitated if hit with axe" do @zombie.status.should eql(:decapitated) endend
  21. 21. Range of TestingIn .NET there are a lot of test frameworksRuby test frameworks include TestUnit, RSpec, Shoulda and CucumberRails encourages testing at all levels.All extremely well documented.
  22. 22. The Rails WayOne project layout and only one layoutPrinciple of least surpriseChange it at your own riskHeavily based on conventions e.g. ZombieController > ZombieControllerSpec Zombie > ZombieSpec (or ZombieTest) Zombie > ZombieControllerThis can be applied to .NET too
  23. 23. The Curse of Active RecordMakes really fast to get going with projectThe number one reason for slow apps (IMHO)Is to easy to write code that over uses the databaseOften don’t/forget to think about DB
  24. 24. The Curse of Active Record1 class Session < ActiveRecord::Base 19 module SessionModel2 # name > string 20 def self.included klass3 # code > string 21 klass.extend ClassMethods 22 end4 235 validates_uniqueness_of :name, :code 24 module ClassMethods6 include SessionModel 25 def code_is_unique?(code)7 26 return self.find_by_code(code).nil?8 def generate_code 27 end 28 end9 return if !(self.code.nil? || 29 end self.code.empty?)10 full_code = ""11 while (true)12 code = "%04d" % rand(9999)13 full_code = “ABC#{code}"14 break if Session.code_is_unique?(full_code)15 end16 self.code = full_code17 end18 endSpot the database calls...
  25. 25. The Curse of Active Recordclass Session < ActiveRecord::Base module SessionModel # name > string def self.included klass # code > string klass.extend ClassMethods end validates_uniqueness_of :name, :code x 2 module ClassMethods include SessionModel def code_is_unique?(code) return self.find_by_code(code).nil? def generate_code end end return if !(self.code.nil? || end self.code.empty?) full_code = "" while (true) code = "%04d" % rand(9999) full_code = “ABC#{code}" break if Session.code_is_unique?(full_code) end self.code = full_code endendThis was production code. The names havebeen changed to protect the innocent
  26. 26. .NET Deployment.NET deployment predominantly through FTP or copy to file shareBut what about databases, migrations, queues, externals dependencies etc.Fear common place on deployment day
  27. 27. Ruby DeploymentDeployment is a solved problem in RailsBuilt on several partsDatabase migration come out of the boxBundler gets dependencyUse of Chef or Capistrano for externals or configuration changesPlatform as a service combine all of these e.g. Heroku, Engineyard, Brightbox
  28. 28. DeploymentShock horror its a demo
  29. 29. From .NET to Rails, A Developers StoryAny Questions?E-mail: pythonandchips@gmail.comBlog: pythonandchips.netTwitter: @colin_gemmell
  30. 30. Rails Scaling
  31. 31. Scaling RailsJohn Adams, Twitter operations http://tinyurl.com/6j4mqqb
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×