Successfully reported this slideshow.

A Tale of Two Rubies

0

Share

Upcoming SlideShare
Getting Your Ruby EGOT
Getting Your Ruby EGOT
Loading in …3
×
1 of 51
1 of 51

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

A Tale of Two Rubies

  1. 1. A Tale of Two Rubies ...with apologies to Charles Dickens
  2. 2. About Me Joshua BallancoName:
  3. 3. About Me Ankara,TurkeyLocation:
  4. 4. About Me Burnside DigitalEmployer:
  5. 5. How many Ruby implementations do you use?
  6. 6. Matz’s Ruby Interpreter JRuby Rubinius IronRuby MacRuby RubyMotion MagLev Cardinal Topaz
  7. 7. What impact do alternate Rubies have on me?
  8. 8. What about fragmentation?
  9. 9. A Story... Once upon a time there was a Rails app, that needed to be ported to JRuby • Ditch C-extensions • Look for JRuby specific versions of gems • Find a good app server • Run your test suite!
  10. 10. What do you do when... ArgumentError: comparison of ActiveSupport::TimeWithZone with ActiveSupport::TimeWithZone failed
  11. 11. A Side Note on Reading Code Read Code
  12. 12. A Side Note on Reading Code Read Code!
  13. 13. A Side Note on Reading Code Read A Lot of Code
  14. 14. A Side Note on Reading Code Read Twice as Much Code asYou Write
  15. 15. A Side Note on Reading Code Read Ten Times as Much Code asYou Write
  16. 16. A Side Note on Reading Code Read Code
  17. 17. Let’s Go Code Diving! activesupport-3.2.13/lib/active_support/time_with_zone.rb
  18. 18. Let’s Go Code Diving!
  19. 19. Confused yet? When was the last time you called TimeWithZone.new anyway???
  20. 20. We Have to go Deeper! activesupport-3.2.13/lib/active_support/core_ext/time/zones.rb activesupport-3.2.13/lib/active_support/core_ext/date_time/zones.rb
  21. 21. We Have to go Deeper! Read Code ...and Comments
  22. 22. So Far... • TimeWithZone initializes @utc to a Time or DateTime • Comparison with <=> passes through “other” to @utc’s <=> operator
  23. 23. But then... ...why?
  24. 24. Remember This?
  25. 25. It Gets Worse...
  26. 26. Remember this?
  27. 27. Oh,ActiveSupport... activesupport-3.2.13/lib/active_support/core_ext/date_time/calculations.rb
  28. 28. Oh,ActiveSupport... activesupport-3.2.13/lib/active_support/core_ext/time/calculations.rb
  29. 29. This isn’t a Rails Talk... Really...it’s not...
  30. 30. Getting to the Heart of the Matter: JRuby • If “other” is a Time object, compare • Otherwise: nil src/org/jruby/RubyTime.java
  31. 31. Getting to the Heart of the Matter: MRI
  32. 32. Getting to the Heart of the Matter: MRI • If “other” is a Time object, compare • If not, call <=> on other, passing self as the argument • If that works, take the negation of the result • Otherwise: nil
  33. 33. So...Fix JRuby
  34. 34. 1 Ruby Down 1 To Go
  35. 35. Always Be Curious
  36. 36. What Classes Reverse Compare Like This? • Time • ... • String • ... • That’s it! BUT!
  37. 37. Oh, MRI...
  38. 38. Break it down... If “other” is a string, do a string comparison (in the else clause...yay)
  39. 39. Break it down... If “other” can not be converted into a string, return nil
  40. 40. Break it down... If “other” also doesn’t have its own comparison operator, return nil
  41. 41. Break it down... If “other” does have its own comparison operator, call it and return the negation of the result BUT! ...
  42. 42. Remember this? Uhh...
  43. 43. Fun With Poorly Specified Behavior ...but I thought <=> only ever returned -1, 0, or 1?
  44. 44. So...Fix MRI
  45. 45. fin? Not quite...
  46. 46. What about... Crap...
  47. 47. Fun With Mutual Recursion
  48. 48. Fun With Mutual Recursion
  49. 49. Fun With Mutual Recursion
  50. 50. The Moral • When MRI was the only game in town, whatever MRI did was “Ruby” • Re-implementing “Ruby” allows us to reconsider behaviors • The key is communication and community
  51. 51. fin Questions?

×