Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby 2.0

Ruby 2.0

「Ruby 2.0」@デブサミ2013

Yukihiro Matsumoto

February 14, 2013
Tweet

More Decks by Yukihiro Matsumoto

Other Decks in Programming

Transcript

  1. Powered by Rabbit 1.0.4
    Ruby 2.0
    Rubyアソシエーション 理事長
    Heroku, Chief Architect, Ruby
    @yukihiro_matz
    Yukihiro "Matz" Matsumoto

    View full-size slide

  2. Powered by Rabbit 1.0.4
     
    2013年
    1/97

    View full-size slide

  3. Powered by Rabbit 1.0.4
     
    1993年
    2/97

    View full-size slide

  4. Powered by Rabbit 1.0.4
     
    1993年2月
    Ruby開発開始
    3/97

    View full-size slide

  5. Powered by Rabbit 1.0.4
     
    1995年12月
    公開(0.95)
    4/97

    View full-size slide

  6. Powered by Rabbit 1.0.4
     
    1996年12月 1.0
    1997年08月 1.1
    1998年12月 1.2
    1999年08月 1.4
    2000年09月 1.6
    5/97

    View full-size slide

  7. Powered by Rabbit 1.0.4
     
    2003年08月 1.8
    2007年12月 1.9.0
    2010年08月 1.9.2
    2011年10月 1.9.3
    6/97

    View full-size slide

  8. Powered by Rabbit 1.0.4
     
    by courtesy of @a_matsuda
    7/97

    View full-size slide

  9. Powered by Rabbit 1.0.4
     
    by courtesy of @a_matsuda
    8/97

    View full-size slide

  10. Powered by Rabbit 1.0.4
     
    とうとうやってきた2.0
    9/97

    View full-size slide

  11. Powered by Rabbit 1.0.4
     
    RubyConf2001
    10/97

    View full-size slide

  12. Powered by Rabbit 1.0.4
    RubyConf2001
    Ruby2に言及
    11/97

    View full-size slide

  13. Powered by Rabbit 1.0.4
    RubyConf2001
    新VM
    新GC
    ネイティブスレッド
    埋込API
    12/97

    View full-size slide

  14. Powered by Rabbit 1.0.4
    RubyConf2001
    心理的壁にも言及
    13/97

    View full-size slide

  15. Powered by Rabbit 1.0.4
    RubyConf2001
    新VM
    新GC
    ネイティブスレッド
    埋込API
    14/97

    View full-size slide

  16. Powered by Rabbit 1.0.4
    RubyConf2001
    コア実装の置き換え
    15/97

    View full-size slide

  17. Powered by Rabbit 1.0.4
    RubyConf2001
    Ruby1.9で実現
    16/97

    View full-size slide

  18. Powered by Rabbit 1.0.4
    新VM
    YARV
    17/97

    View full-size slide

  19. Powered by Rabbit 1.0.4
    新GC
    世代別GC
    18/97

    View full-size slide

  20. Powered by Rabbit 1.0.4
    新GC
    性能低下のため不採用
    19/97

    View full-size slide

  21. Powered by Rabbit 1.0.4
    新GC
    Ruby1.9でLazy Sweep
    20/97

    View full-size slide

  22. Powered by Rabbit 1.0.4
    新GC
    Ruby2.0でbitmap marking
    21/97

    View full-size slide

  23. Powered by Rabbit 1.0.4
    ネイティブスレッド
    1.8はグリーンスレッド
    22/97

    View full-size slide

  24. Powered by Rabbit 1.0.4
    ネイティブスレッド
    1.9はネイティブスレッド
    23/97

    View full-size slide

  25. Powered by Rabbit 1.0.4
    ネイティブスレッド
    GIL
    24/97

    View full-size slide

  26. Powered by Rabbit 1.0.4
    GIL
    Giant Interpreter Lock
    25/97

    View full-size slide

  27. Powered by Rabbit 1.0.4
    GIL
    妥協点
    26/97

    View full-size slide

  28. Powered by Rabbit 1.0.4
    埋込API
    互換性重視のため不採用
    27/97

    View full-size slide

  29. Powered by Rabbit 1.0.4
     
    2001年のRuby2
    28/97

    View full-size slide

  30. Powered by Rabbit 1.0.4
     
    2007年のRuby1.9
    29/97

    View full-size slide

  31. Powered by Rabbit 1.0.4
     
    現代のRuby2.0の起源
    30/97

    View full-size slide

  32. Powered by Rabbit 1.0.4
     
    RubyConf2003
    31/97

    View full-size slide

  33. Powered by Rabbit 1.0.4
    RubyConf2003
    キーワード引数
    新ハッシュリテラル
    メソッドコンビネーション
    セレクターネームスペース
    32/97

    View full-size slide

  34. Powered by Rabbit 1.0.4
     
    遅れてきた2.0
    33/97

    View full-size slide

  35. Powered by Rabbit 1.0.4
    RubyConf2001
    心理的壁に言及
    34/97

    View full-size slide

  36. Powered by Rabbit 1.0.4
     
    壁を乗り越える原因
    35/97

    View full-size slide

  37. Powered by Rabbit 1.0.4
    心理的側面
    20周年記念
    36/97

    View full-size slide

  38. Powered by Rabbit 1.0.4
    心理的側面
    Anniversary Driven Development
    37/97

    View full-size slide

  39. Powered by Rabbit 1.0.4
    心理的側面
    ADD
    38/97

    View full-size slide

  40. Powered by Rabbit 1.0.4
    機能的側面
    キーワード引数 (2.0)
    メソッドコンビネーション (2.0)
    セレクターネームスペース (2.0)
    39/97

    View full-size slide

  41. Powered by Rabbit 1.0.4
     
    2.0の新機能
    40/97

    View full-size slide

  42. Powered by Rabbit 1.0.4
    2.0の新機能
    キーワード引数
    Module#prepend
    Enumerable#lazy
    Refinements
    41/97

    View full-size slide

  43. Powered by Rabbit 1.0.4
    2.0の新機能
    デフォルトUTF-8
    Dtrace
    TracePoint
    Performance
    42/97

    View full-size slide

  44. Powered by Rabbit 1.0.4
    キーワード引数
    名前付きオプショナル引数
    順序不定
    記述性
    記憶想起
    43/97

    View full-size slide

  45. Powered by Rabbit 1.0.4
    キーワード引数
    def downto(from, to, step: 1)
    ...
    end
    downto(10, 0, step:2) do|i|
    p i
    end
    44/97

    View full-size slide

  46. Powered by Rabbit 1.0.4
    キーワード引数
    APIの柔軟性
    ドキュメント化
    読みやすさ
    覚えやすさ
    45/97

    View full-size slide

  47. Powered by Rabbit 1.0.4
    Module#prepend
    メソッドコンビネーション
    既存のクラスの修飾
    alias method chain
    46/97

    View full-size slide

  48. Powered by Rabbit 1.0.4
    alias method chain
    alias(別名)によって定義を連鎖
    Railsで多用される
    既存メソッドの拡張
    47/97

    View full-size slide

  49. Powered by Rabbit 1.0.4
    alias method chainの欠点
    名前衝突の危険性
    名前管理
    修飾のグループ化が困難
    48/97

    View full-size slide

  50. Powered by Rabbit 1.0.4
    メソッドコンビネーション
    CLOS(CommonLisp Object
    System)
    メソッドを拡張する仕組み
    MOP
    49/97

    View full-size slide

  51. Powered by Rabbit 1.0.4
    メソッドコンビネーション
    beforeフック
    afterフック
    aroundフック
    50/97

    View full-size slide

  52. Powered by Rabbit 1.0.4
    メソッドコンビネーション
    Rubyにはオーバースペック
    51/97

    View full-size slide

  53. Powered by Rabbit 1.0.4
    Module#prepend
    単純化メソッドコンビネーション
    52/97

    View full-size slide

  54. Powered by Rabbit 1.0.4
    Module#prepend
    prepend
    includeは後ろに追加
    prependは前に追加
    既存のメソッドをラップ
    53/97

    View full-size slide

  55. 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
    54/97

    View full-size slide

  56. Powered by Rabbit 1.0.4
    prepend vs chain
    名称重複問題
    グループ化問題
    55/97

    View full-size slide

  57. Powered by Rabbit 1.0.4
    Refinements
    既存クラスの拡張
    56/97

    View full-size slide

  58. Powered by Rabbit 1.0.4
    既存クラスの拡張
    メソッドの追加
    メソッドのラップ
    57/97

    View full-size slide

  59. Powered by Rabbit 1.0.4
    既存クラスの拡張
    オープンクラス
    クラス再定義
    mathn, jcode
    58/97

    View full-size slide

  60. Powered by Rabbit 1.0.4
    既存クラスの拡張
    スコープ問題
    59/97

    View full-size slide

  61. Powered by Rabbit 1.0.4
    Refinements
    スコープ限定のオープンクラス
    60/97

    View full-size slide

  62. Powered by Rabbit 1.0.4
    Refinements
    module R
    refine String do
    def foo
    ...
    end
    end
    end
    "".foo # => error!
    using R
    "".foo
    61/97

    View full-size slide

  63. Powered by Rabbit 1.0.4
    既存クラス拡張の試み
    Selector namespace
    (Smallscript)
    Classbox (Smalltalk/Java)
    拡張メソッド (C#)
    プロファイル (Classic)
    62/97

    View full-size slide

  64. Powered by Rabbit 1.0.4
    Selector namespace
    「メッセージ」の多重化
    挙動が難しい
    Smallscriptが入手困難
    63/97

    View full-size slide

  65. Powered by Rabbit 1.0.4
    Classbox
    既存のクラスを置き換える
    例:GUIのルック・アンド・フィール
    変更
    ローカルリバインディング
    64/97

    View full-size slide

  66. Powered by Rabbit 1.0.4
    ローカルリバインディング
    スコープ問題
    動的スコープ
    変更の影響範囲が大きい
    65/97

    View full-size slide

  67. Powered by Rabbit 1.0.4
    拡張メソッド
    メソッドの追加しかできない
    Scalaも同様?
    66/97

    View full-size slide

  68. Powered by Rabbit 1.0.4
    プロファイル
    ひとつの構造体に複数のインタフ
    ェース
    「プロファイル」
    相互に代入可能
    67/97

    View full-size slide

  69. Powered by Rabbit 1.0.4
    プロファイル
    静的型言語向け
    24年前のアイディア
    他に見かけない
    68/97

    View full-size slide

  70. Powered by Rabbit 1.0.4
    Enumerable#lazy
    遅延評価
    69/97

    View full-size slide

  71. Powered by Rabbit 1.0.4
    Enumerable#lazy
    関数型(?)プログラミング
    70/97

    View full-size slide

  72. Powered by Rabbit 1.0.4
    Enumerable#lazy
    関数型ワナビー
    71/97

    View full-size slide

  73. Powered by Rabbit 1.0.4
    関数型ワナビー
    イミュータブルデータ
    パターンマッチ
    遅延評価
    関数組立
    72/97

    View full-size slide

  74. Powered by Rabbit 1.0.4
    関数組立
    ほぼメソッドチェーン
    73/97

    View full-size slide

  75. Powered by Rabbit 1.0.4
    メソッドチェーン
    (1..Float::INFINITY).map {|i|
    i.to_s
    }.select{|s|
    /3/ === s
    }.first(5)
    74/97

    View full-size slide

  76. Powered by Rabbit 1.0.4
    メソッドチェーン
    動かない
    75/97

    View full-size slide

  77. Powered by Rabbit 1.0.4
    メソッドチェーン
    遅延評価さえあれば...
    76/97

    View full-size slide

  78. Powered by Rabbit 1.0.4
    遅延評価
    遅延評価するバージョンのメソッド
    77/97

    View full-size slide

  79. Powered by Rabbit 1.0.4
    遅延評価
    map_lz, select_lz
    78/97

    View full-size slide

  80. Powered by Rabbit 1.0.4
    メソッドチェーン
    (1..Float::INFINITY).map_lz {|i|
    i.to_s
    }.select_lz{|s|
    /3/ === s
    }.first(5)
    79/97

    View full-size slide

  81. Powered by Rabbit 1.0.4
    遅延評価
    遅延(lazy)を求めるものはlazy(怠惰)
    である
    80/97

    View full-size slide

  82. Powered by Rabbit 1.0.4
    Enumerable#lazy
    (1..Float::INFINITY).lazy.map {|i|
    i.to_s
    }.select{|s|
    /3/ === s
    }.first(5)
    81/97

    View full-size slide

  83. Powered by Rabbit 1.0.4
    Enumerable#lazy
    ナイスアイディア
    82/97

    View full-size slide

  84. Powered by Rabbit 1.0.4
    Enumerable#lazy
    中身はいろいろ大変
    83/97

    View full-size slide

  85. Powered by Rabbit 1.0.4
    デフォルトUTF-8
    Unicode浸透
    84/97

    View full-size slide

  86. Powered by Rabbit 1.0.4
    デフォルトUTF-8
    普通にUTF-8
    85/97

    View full-size slide

  87. Powered by Rabbit 1.0.4
    Dtrace/TracePoint
    デバッグ強化
    86/97

    View full-size slide

  88. Powered by Rabbit 1.0.4
    Performance
    高速化
    87/97

    View full-size slide

  89. Powered by Rabbit 1.0.4
    高速化
    VM
    GC
    require
    88/97

    View full-size slide

  90. Powered by Rabbit 1.0.4
     
    Ruby 2.0
    89/97

    View full-size slide

  91. Powered by Rabbit 1.0.4
    Ruby 2.0
    2013年2月24日リリース予定
    90/97

    View full-size slide

  92. Powered by Rabbit 1.0.4
    Ruby 2.0
    乞御期待
    91/97

    View full-size slide

  93. Powered by Rabbit 1.0.4
    Ruby 2.0以後
    言語としてはほぼ完成
    92/97

    View full-size slide

  94. Powered by Rabbit 1.0.4
    Ruby 2.0以後
    Ruby言語の限界
    93/97

    View full-size slide

  95. Powered by Rabbit 1.0.4
    Ruby 2.0以後
    性能改善
    94/97

    View full-size slide

  96. Powered by Rabbit 1.0.4
    Ruby 2.0以後
    適用分野拡大
    95/97

    View full-size slide

  97. Powered by Rabbit 1.0.4
    Ruby 2.0以後
    マルチコア?
    96/97

    View full-size slide

  98. Powered by Rabbit 1.0.4
    Ruby 2.0以後
    アクター?
    97/97

    View full-size slide