A Tale of Two Rubies

587 views

Published on

Slides from the talk "A Tale of Two Rubies" that I presented at the RuLu 2013 conference.

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
587
On SlideShare
0
From Embeds
0
Number of Embeds
41
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A Tale of Two Rubies

  1. 1. A Tale of Two Rubies...with apologies to Charles Dickens
  2. 2. About MeJoshua BallancoName:
  3. 3. About MeAnkara,TurkeyLocation:
  4. 4. About MeBurnside DigitalEmployer:
  5. 5. How many Rubyimplementations doyou use?
  6. 6. Matz’s Ruby InterpreterJRubyRubiniusIronRubyMacRubyRubyMotionMagLev CardinalTopaz
  7. 7. What impact doalternate Rubies haveon me?
  8. 8. What aboutfragmentation?
  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 dowhen...ArgumentError: comparison of ActiveSupport::TimeWithZonewith ActiveSupport::TimeWithZone failed
  11. 11. A Side Note onReading CodeRead Code
  12. 12. A Side Note onReading CodeRead Code!
  13. 13. A Side Note onReading CodeRead A Lot of Code
  14. 14. A Side Note onReading CodeRead Twice as MuchCode asYou Write
  15. 15. A Side Note onReading CodeRead Ten Times as MuchCode asYou Write
  16. 16. A Side Note onReading CodeRead 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 calledTimeWithZone.new anyway???
  20. 20. We Have to goDeeper!activesupport-3.2.13/lib/active_support/core_ext/time/zones.rbactivesupport-3.2.13/lib/active_support/core_ext/date_time/zones.rb
  21. 21. We Have to goDeeper!Read Code...and Comments
  22. 22. So Far...• TimeWithZone initializes @utc to a Timeor 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 ofthe Matter: JRuby• If “other” is a Time object, compare• Otherwise: nilsrc/org/jruby/RubyTime.java
  31. 31. Getting to the Heart ofthe Matter: MRI
  32. 32. Getting to the Heart ofthe Matter: MRI• If “other” is a Time object, compare• If not, call <=> on other, passing self as theargument• If that works, take the negation of theresult• Otherwise: nil
  33. 33. So...Fix JRuby
  34. 34. 1 Ruby Down1 To Go
  35. 35. AlwaysBeCurious
  36. 36. What Classes ReverseCompare 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 convertedinto a string, return nil
  40. 40. Break it down...If “other” also doesn’t have its owncomparison operator, return nil
  41. 41. Break it down...If “other” does have its owncomparison operator, call it andreturn the negation of the resultBUT! ...
  42. 42. Remember this?Uhh...
  43. 43. Fun With PoorlySpecified Behavior...but I thought <=> only everreturned -1, 0, or 1?
  44. 44. So...Fix MRI
  45. 45. fin?Not quite...
  46. 46. What about...Crap...
  47. 47. Fun With MutualRecursion
  48. 48. Fun With MutualRecursion
  49. 49. Fun With MutualRecursion
  50. 50. The Moral• When MRI was the only game in town,whatever MRI did was “Ruby”• Re-implementing “Ruby” allows us toreconsider behaviors• The key is communication and community
  51. 51. finQuestions?

×