Ruby 2.0 (en)

Ruby 2.0 (en)

Ruby 2.0 at Waza 2013 (English version)

9fd98ce2546f50257873c2f23e95d293?s=128

Yukihiro Matsumoto

March 01, 2013
Tweet

Transcript

  1. Powered by Rabbit 1.0.4 Ruby 2.0 Chief Architect, Ruby @

    Heroku @yukihiro_matz Yukihiro "Matz" Matsumoto
  2. Powered by Rabbit 1.0.4   Ruby1.8 will die soon 1/143

  3. Powered by Rabbit 1.0.4   Move to Ruby2.0 now 2/143

  4. Powered by Rabbit 1.0.4   1.8.7 3/143

  5. Powered by Rabbit 1.0.4   Rails tragedy 4/143

  6. Powered by Rabbit 1.0.4   1.9.0 5/143

  7. Powered by Rabbit 1.0.4   Compatibility tragedy 6/143

  8. Powered by Rabbit 1.0.4   Ruby2.0 7/143

  9. Powered by Rabbit 1.0.4   The happiest release ever 8/143

  10. Powered by Rabbit 1.0.4   Faster 9/143

  11. Powered by Rabbit 1.0.4   Better 10/143

  12. Powered by Rabbit 1.0.4   `100% Compatible' 11/143

  13. Powered by Rabbit 1.0.4   February 24 1993 12/143

  14. Powered by Rabbit 1.0.4   I started developing Ruby 13/143

  15. Powered by Rabbit 1.0.4   The date I named it

    14/143
  16. Powered by Rabbit 1.0.4   December 21 1995 15/143

  17. Powered by Rabbit 1.0.4   I released it to public

    (0.95) 16/143
  18. Powered by Rabbit 1.0.4   Dec 1996 1.0 Aug 1997

    1.1 Dec 1998 1.2 Aug 1999 1.4 Sep 2000 1.6 17/143
  19. Powered by Rabbit 1.0.4   Aug 2003 1.8 Dec 2007

    1.9.0 Aug 2010 1.9.2 Oct 2011 1.9.3 18/143
  20. Powered by Rabbit 1.0.4   by courtesy of @a_matsuda 19/143

  21. Powered by Rabbit 1.0.4   by courtesy of @a_matsuda 20/143

  22. Powered by Rabbit 1.0.4   We released Ruby2.0 21/143

  23. Powered by Rabbit 1.0.4   Finally 22/143

  24. Powered by Rabbit 1.0.4   On Faburary 24th 2013 23/143

  25. Powered by Rabbit 1.0.4   Ruby's 20th birthday 24/143

  26. Powered by Rabbit 1.0.4   RubyConf2001 25/143

  27. Powered by Rabbit 1.0.4 RubyConf2001 I mentioned Ruby2 26/143

  28. Powered by Rabbit 1.0.4 RubyConf2001 new VM new GC native

    thread embeddable API 27/143
  29. Powered by Rabbit 1.0.4 RubyConf2001 I also mentioned psychological barrier

    28/143
  30. Powered by Rabbit 1.0.4 Version Numbers limited resource 29/143

  31. Powered by Rabbit 1.0.4 Psychological Barrier 20 years anniversary 30/143

  32. Powered by Rabbit 1.0.4 Psychological Barrier Anniversary Driven Development 31/143

  33. Powered by Rabbit 1.0.4 Psychological Barrier ADD 32/143

  34. Powered by Rabbit 1.0.4 RubyConf2001 new VM new GC native

    thread embeddable API 33/143
  35. Powered by Rabbit 1.0.4 new VM for performance 34/143

  36. Powered by Rabbit 1.0.4 new VM Implemented by Ruby1.9 (YARV)

    35/143
  37. Powered by Rabbit 1.0.4 new GC GC performance 36/143

  38. Powered by Rabbit 1.0.4 new GC Generatoinal GC 37/143

  39. Powered by Rabbit 1.0.4 new GC Gave up 38/143

  40. Powered by Rabbit 1.0.4 new GC Ruby1.9 improved GC 39/143

  41. Powered by Rabbit 1.0.4 new GC Lazy Sweeping 40/143

  42. Powered by Rabbit 1.0.4 new GC Bitmap marking (2.0) 41/143

  43. Powered by Rabbit 1.0.4 native thread green thread til 1.8

    42/143
  44. Powered by Rabbit 1.0.4 native thread stack copying 43/143

  45. Powered by Rabbit 1.0.4 native thread linking threading library problem

    44/143
  46. Powered by Rabbit 1.0.4 native thread Ruby1.9 uses native thread

    45/143
  47. Powered by Rabbit 1.0.4 native thread with GIL 46/143

  48. Powered by Rabbit 1.0.4 native thread Giant Interpreter Lock 47/143

  49. Powered by Rabbit 1.0.4 native thread thread safe core 48/143

  50. Powered by Rabbit 1.0.4 native thread fine grained lock problem

    49/143
  51. Powered by Rabbit 1.0.4 native thread Compromise 50/143

  52. Powered by Rabbit 1.0.4 embeddable API Gave up 51/143

  53. Powered by Rabbit 1.0.4 embeddable API Compatibility matters 52/143

  54. Powered by Rabbit 1.0.4   Ruby2 in 2001 53/143

  55. Powered by Rabbit 1.0.4   Done in Ruby1.9 54/143

  56. Powered by Rabbit 1.0.4   The origin of Ruby2.0 today

    55/143
  57. Powered by Rabbit 1.0.4   RubyConf2003 56/143

  58. Powered by Rabbit 1.0.4 RubyConf2003 New Hash literals Keyword arguments

    Method combination Selector namespace 57/143
  59. Powered by Rabbit 1.0.4 New Hash literals {:foo => 1,

    :bar => 2} as {foo: 1, bar: 2} 58/143
  60. Powered by Rabbit 1.0.4 New Hash literals Done in 1.9

    59/143
  61. Powered by Rabbit 1.0.4 Method combination Allowing method decoration 60/143

  62. Powered by Rabbit 1.0.4 Selector namespace Monkey patching with scope

    61/143
  63. Powered by Rabbit 1.0.4   New features in Ruby2.0 62/143

  64. Powered by Rabbit 1.0.4 New features in 2.0 Keyword arguments

    Module#prepend Enumerable#lazy Refinements 63/143
  65. Powered by Rabbit 1.0.4 New features in 2.0 symbol array

    literals to_h conversion method UTF-8 by default Dtrace / TracePoint 64/143
  66. Powered by Rabbit 1.0.4   Keyword Arguments 65/143

  67. Powered by Rabbit 1.0.4 Keyword Arguments Named optinal arguments No

    specific order Descriptive Easy-to-remember 66/143
  68. Powered by Rabbit 1.0.4 Keyword Arguments log("Hello!", level: "INFO") Possoble

    in Ruby1.9 67/143
  69. Powered by Rabbit 1.0.4 Keyword Arguments in 1.9 def log(msg,

    opt = {}) level = opt[:level] || "ERROR" time = opt[:time] || Time.now puts "#{ time.ctime } [#{ level }] #{ msg }" end 68/143
  70. Powered by Rabbit 1.0.4 Keyword Arguments in 1.9 What if

    you want to combin with arbitrary number of arguments descriptive exceptions pass nil as a valid value 69/143
  71. Powered by Rabbit 1.0.4 Keyword Arguments in 1.9 def log(*msgs)

    opt = msgs.last.is_a?(Hash) ? msgs.pop : {} level = opt.key?(:level) ? opt.delete(:level) : "ERROR" time = opt.key?(:time) ? opt.delete(:time) : Time.now raise "unknown keyword: #{ opt.keys.first }" if !opt.empty? msgs.each {|msg| puts "#{ time.ctime } [#{ level }] #{ msg }" } end 70/143
  72. Powered by Rabbit 1.0.4 Keyword Arguments in 2.0 def log(msg,

    level: "ERROR", time: Time.now) puts "#{ time.ctime } [#{ level }] #{ msg }" end 71/143
  73. Powered by Rabbit 1.0.4 Keyword Arguments in 2.0 Simpler More

    descriptive API Easy to read Easy to write 72/143
  74. Powered by Rabbit 1.0.4 Keyword Arguments in 2.0 log("Hello!", **opt)

    You can pass existing hash as keyword arguments 73/143
  75. Powered by Rabbit 1.0.4 Keyword Arguments in 2.0 def log(msg,

    level: "ERROR", time: Time.now, **kw) puts "#{ time.ctime } [#{ level }] #{ msg }" end You can get keyword arguments as a hash Unkown keywords do not raise error 74/143
  76. Powered by Rabbit 1.0.4 Keyword Arguments in 2.0 Summary Easy

    API More descriptive Rails prefer keyword arguments 75/143
  77. Powered by Rabbit 1.0.4   Module#prepend 76/143

  78. Powered by Rabbit 1.0.4 Module#prepend Method combination Decrating existing methods

    77/143
  79. Powered by Rabbit 1.0.4 alias method chain Decorate existing methods

    using aliases AcriveSupport 78/143
  80. Powered by Rabbit 1.0.4 alias method chain class A def

    foo; puts "foo"; end end class A # reopen def foo_with_bar foo_without_bar puts "bar" end alias_method_chain :foo, :bar end A.new.foo 79/143
  81. Powered by Rabbit 1.0.4 alias method chain def alias_method_chain(target, feature)

    alias_method "#{target}_without_#{feature}", target alias_method target, "#{target}_with_#{feature}" end 80/143
  82. Powered by Rabbit 1.0.4 alias method chain problems many public

    methods spilled out accidental feature name conflict adding same feature set to classes 81/143
  83. Powered by Rabbit 1.0.4 Method combination from CLOS(CommonLisp Object System)

    to extend existing methods confugurable via MOP 82/143
  84. Powered by Rabbit 1.0.4 Method combination Standard combination in CLOS

    before hook after hook around hook 83/143
  85. Powered by Rabbit 1.0.4 Method combination Confugurable via MOP and-combination

    or-combination whatever-combination 84/143
  86. Powered by Rabbit 1.0.4 Method combination in CLOS Too complex

    for Ruby 85/143
  87. Powered by Rabbit 1.0.4 Module#prepend Simplified Method Comnbination 86/143

  88. Powered by Rabbit 1.0.4 Module#prepend Methods added by #include comes

    after exisiting methods #prepend put them before to wrap methods 87/143
  89. Powered by Rabbit 1.0.4 Module#prepend class Foo def foo; p

    :foo; end end module Prepend def foo p :before super p :after end end class Foo prepend Prepend end Foo.new.foo 88/143
  90. Powered by Rabbit 1.0.4 Module#prepend Summary Extending exising methods No

    method name conflict Package features in a module 89/143
  91. Powered by Rabbit 1.0.4   Refinements 90/143

  92. Powered by Rabbit 1.0.4 Refinements Scoped Monkey Patching 91/143

  93. Powered by Rabbit 1.0.4 Monkey Patching Open class Reopen existing

    class/module Adding methods Replacing methods 92/143
  94. Powered by Rabbit 1.0.4 Adding methods ActiveSupport 93/143

  95. Powered by Rabbit 1.0.4 Adding methods 20.years.ago # => Sun

    Feb 28 17:32:42 94/143
  96. Powered by Rabbit 1.0.4 Replacing methods mathn 95/143

  97. Powered by Rabbit 1.0.4 Replacing methods 1 / 2 #=>

    0 96/143
  98. Powered by Rabbit 1.0.4 Replacing methods require 'mathn' 1 /

    2 #=> 1/2 (Rational) 97/143
  99. Powered by Rabbit 1.0.4   Open class is so strong

    98/143
  100. Powered by Rabbit 1.0.4   Any Problem? 99/143

  101. Powered by Rabbit 1.0.4 Problems Name conflict Behavior conflict 100/143

  102. Powered by Rabbit 1.0.4   Global modification is bad 101/143

  103. Powered by Rabbit 1.0.4 Scoped enhancement Refinement 102/143

  104. Powered by Rabbit 1.0.4 Refinements module R refine String do

    def foo ... end end end "".foo # => error! using R "".foo 103/143
  105. Powered by Rabbit 1.0.4 Other Languages Selector namespace (Smallscript) Classbox

    (Smalltalk/Java) Extended Method (C#) 104/143
  106. Powered by Rabbit 1.0.4 Selector namespace No one knows Smallscript

    Smallscript still alive? Very complex 105/143
  107. Powered by Rabbit 1.0.4 Classbox Scoped class modification Local rebinding

    Dynamic scope 106/143
  108. Powered by Rabbit 1.0.4 Extended Methods Can only add methods

    No replacing 107/143
  109. Powered by Rabbit 1.0.4   Enumerable#lazy 108/143

  110. Powered by Rabbit 1.0.4 Enumerable#lazy for Lazy evaluation 109/143

  111. Powered by Rabbit 1.0.4 Enumerable#lazy Inspired by functional programming 110/143

  112. Powered by Rabbit 1.0.4 Enumerable#lazy Functional programming wannabe 111/143

  113. Powered by Rabbit 1.0.4 Functional programming wannabe Immutable data Pattern

    matching Lazy evaluation Function composition 112/143
  114. Powered by Rabbit 1.0.4 Function composition sort of method chains

    in Ruby 113/143
  115. Powered by Rabbit 1.0.4 Method chains (1..Float::INFINITY).map {|i| i.to_s }.select{|s|

    /3/ === s }.first(5) This doesn't work 114/143
  116. Powered by Rabbit 1.0.4 Method chains If we had lazy

    evaluation.. 115/143
  117. Powered by Rabbit 1.0.4 Lazy evaluation What if we had

    lazy version of enumerating methods 116/143
  118. Powered by Rabbit 1.0.4 Lazy evaluation map_lz, select_lz 117/143

  119. Powered by Rabbit 1.0.4 Method chains (1..Float::INFINITY).map_lz {|i| i.to_s }.select_lz{|s|

    /3/ === s }.first(5) 118/143
  120. Powered by Rabbit 1.0.4 Lazy evaluation Lazy people need lazy

    evaluation 119/143
  121. Powered by Rabbit 1.0.4 Lazy evaluation to lazy to add

    _lz all the time 120/143
  122. Powered by Rabbit 1.0.4 Enumerable#lazy (1..Float::INFINITY).lazy.map {|i| i.to_s }.select{|s| /3/

    === s }.first(5) 121/143
  123. Powered by Rabbit 1.0.4 Enumerable#lazy Looks better 122/143

  124. Powered by Rabbit 1.0.4   Symbol array literals 123/143

  125. Powered by Rabbit 1.0.4 Symbol array literals %i(foo bar baz)

    124/143
  126. Powered by Rabbit 1.0.4   to_h conversion method 125/143

  127. Powered by Rabbit 1.0.4 to_h conversion method Hash, ENV, Struct

    to have to_h 126/143
  128. Powered by Rabbit 1.0.4 to_i and to_int to_i for explicit

    conversion to_int for implicit conversion 127/143
  129. Powered by Rabbit 1.0.4 conversion methods to_i and to_int to_s

    and to_str to_h and to_hash 128/143
  130. Powered by Rabbit 1.0.4   UTF-8 by default 129/143

  131. Powered by Rabbit 1.0.4 UTF-8 by default No magic comment

    needed 130/143
  132. Powered by Rabbit 1.0.4 UTF-8 by default Unicode everywhere now

    131/143
  133. Powered by Rabbit 1.0.4 Dtrace/TracePoint Better debug/profile support 132/143

  134. Powered by Rabbit 1.0.4 Performance VM GC require 133/143

  135. Powered by Rabbit 1.0.4   Ruby 2.0 134/143

  136. Powered by Rabbit 1.0.4   Now works on Heroku 135/143

  137. Powered by Rabbit 1.0.4   136/143

  138. Powered by Rabbit 1.0.4 Ruby2.0 working under the platform 137/143

  139. Powered by Rabbit 1.0.4 Ruby2.0 and beyond I have no

    idea (yet) 138/143
  140. Powered by Rabbit 1.0.4 Ruby2.1 We made a 2.1 branch

    139/143
  141. Powered by Rabbit 1.0.4 Ruby2.1 Coming next Christmas (hopefull) 140/143

  142. Powered by Rabbit 1.0.4 Ruby2.1 less strict Unicode validation even

    better perfomance 141/143
  143. Powered by Rabbit 1.0.4   Thank you 142/143

  144. Powered by Rabbit 1.0.4   Any Questions? 143/143