6. My First Ruby Development Environment Window XP/Vista/7 Rubymine Cygwin Ruby Gems Interactive Ruby Console (irb)
7. Windows Problems Rails traditionally deployed on Linux OS Gem’s often use Linux kernal methods or Linux Libraries Engineyard investing on Rails development with windows
8. Development Environment VMware workstation Ubuntu Rubymine VIM + a lot of plugins Ruby Gems Interactive Ruby Console (irb)
11. Ruby and SOLID Single responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Injection
12. Ruby and loose coupling In .NET we use Interface and Dependency Injection to achieve loose coupling Ruby is loosely coupled by design. Everything and anything can be changed. Thanks to being a dynamic language and……
14. Add New Functionality to Ruby "Developer DeveloperDeveloper is awesome".second_word NoMethodError: undefined method `second_word' for "developer developerdeveloper":String classString defsecond_work returnself.split(' ')[1] end end "Developer DeveloperDeveloper is awesome".second_word === “Developer” Extension methods anyone?
15. Changing implementation classZombieKiller defkill self.shotgun.fire end end zombie_killer=ZombieKiller.new puts(zombie_killer.kill) ===Zombieheadexplodes classZombieKiller defkill self.axe.throw end end zombie_killer=ZombieKiller.new puts(zombie_killer.kill) ===ZombieFalls off
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 you've learned to use? Monkey patching can be incredibly dangerous in the wrong hands. Jeff Atwood http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html
18. Testing Ruby and Rails Testing ensures code behaves correctly Tests ensure code compiles Debugging support patchy at best Its all right, testing is a lot simpler
20. Example RSpec test classZombieKiller defkillzombie zombie.attack_withself.weapon end End classZombie<ActiveRecord::Base defattack_withweapon #do some logic to see #what happened to zombie self.save end end describe"when killing a zombie"do classZombie defsave true end end beforedo @zombie=Zombie.new( :strength=>:week,:speed=>:fast) @zombie_killer=ZombieKiller.new( :weapon=>:axe) @zombie_killer.kill(@zombie) end it"should be decapitated if hit with axe"do @zombie.status.shouldeql(:decapitated) end end
21. Range of Testing In .NET there are a lot of test frameworks Ruby test frameworks include TestUnit, RSpec, Shoulda and Cucumber Rails encourages testing at all levels. All extremely well documented.
22. The Rails Way One project layout and only one layout Principle of least surprise Change it at your own risk Heavily based on conventions e.g. ZombieController > ZombieControllerSpec Zombie > ZombieSpec (or ZombieTest) Zombie > ZombieController This can be applied to .NET too
23. Makes really fast to get going with project The number one reason for slow apps (IMHO) Is to easy to write code that over uses the database Often don’t/forget to think about DB The Curse of Active Record
24. The Curse of Active Record 1 classSession<ActiveRecord::Base 2 # name > string 3 # code > string 4 5 validates_uniqueness_of:name,:code 6 includeSessionModel 7 8 defgenerate_code 9 returnif!(self.code.nil?||self.code.empty?) 10 full_code="" 11 while(true) 12 code="%04d"%rand(9999) 13 full_code=“ABC#{code}" 14 breakifSession.code_is_unique?(full_code) 15 end 16 self.code=full_code 17 end 18 end 19 moduleSessionModel 20 defself.includedklass 21 klass.extendClassMethods 22 end 23 24 moduleClassMethods 25 defcode_is_unique?(code) 26 returnself.find_by_code(code).nil? 27 end 28 end 29 end Spot the database calls...
25. The Curse of Active Record classSession<ActiveRecord::Base # name > string # code > string validates_uniqueness_of:name,:code x 2 includeSessionModel defgenerate_code returnif!(self.code.nil?||self.code.empty?) full_code="" while(true) code="%04d"%rand(9999) full_code=“ABC#{code}" breakifSession.code_is_unique?(full_code) end self.code=full_code end end moduleSessionModel defself.includedklass klass.extendClassMethods end moduleClassMethods defcode_is_unique?(code) returnself.find_by_code(code).nil? end end end This was production code. The names have been changed to protect the innocent
26. .NET deployment predominantly through FTP or copy to file share But what about databases, migrations, queues, externals dependencies etc. Fear common place on deployment day .NET Deployment
27. Deployment is a solved problem in Rails Built on several parts Database migration come out of the box Bundler gets dependency Use of Chef or Capistrano for externals or configuration changes Platform as a service combine all of these e.g. Heroku, Engineyard, Brightbox Ruby Deployment
30. From .NET to Rails, A Developers Story Any Questions? E-mail: pythonandchips@gmail.com Blog: pythonandchips.net Twitter: @colin_gemmell Today’s Sponsors