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

Ruby 3.0: Redux (Saint P RubyConf 2019)

Ruby 3.0: Redux (Saint P RubyConf 2019)

Bozhidar Batsov

June 01, 2019
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. Привет,
    ребята!

    View full-size slide

  2. Божидар

    View full-size slide

  3. Божо
    cool

    View full-size slide

  4. Божи дар

    View full-size slide

  5. Божий дар

    View full-size slide

  6. Батсов

    View full-size slide

  7. Sofia, Bulgaria
    Sofia, Bulgaria

    View full-size slide

  8. Bulgarian Cheese

    View full-size slide

  9. Болгарка

    View full-size slide

  10. Слънчев Бряг

    View full-size slide

  11. Златни пясъци

    View full-size slide

  12. Банско

    View full-size slide

  13. Луканка

    View full-size slide

  14. Rakia
    Connecting People

    View full-size slide

  15. Shopska Salad
    (use only with Rakia)

    View full-size slide

  16. metaredux.com

    View full-size slide

  17. Много городов у нас в России,
    Нету пальцев столько на ногах,
    С каждым годом всё они красивей,
    Утопают в солнце и в снегах.

    View full-size slide

  18. Not on Ruby’s Core Team

    View full-size slide

  19. Ruby & Rails
    style guides

    View full-size slide

  20. Language Maturity

    View full-size slide

  21. The Ruby Community

    View full-size slide

  22. Ruby is not dying

    View full-size slide

  23. We have to feed the
    community intellectually.
    — Matz

    View full-size slide

  24. We have to keep moving
    forward.
    — Matz

    View full-size slide

  25. Backwards Compatibility

    View full-size slide

  26. We’re not going to repeat the
    Python 3 mistakes!
    — Matz

    View full-size slide

  27. Victim of the Hype Cycle

    View full-size slide

  28. Rails Mania (2008)

    View full-size slide

  29. Matz’s Retirement

    View full-size slide

  30. Ruby 4 is going to be 4 times
    faster than Ruby 3

    View full-size slide

  31. Ruby 4 is going to be 12 times
    faster than Ruby 2

    View full-size slide

  32. Ruby 4 is finally going to be
    fast enough!

    View full-size slide

  33. What about Ruby 3?

    View full-size slide

  34. –Matz
    “We’ll aim to release Ruby 3 for the Olympic
    Games in Tokyo in 2020.”

    View full-size slide

  35. Ruby 3 Goals
    •Improved programming safety
    •Faster performance
    •Better concurrency/parallelism support
    •Better tools

    View full-size slide

  36. Optional static typing?

    View full-size slide

  37. Duck inference?

    View full-size slide

  38. Stream based model?

    View full-size slide

  39. Ownership based model?

    View full-size slide

  40. 3 times faster performance?

    View full-size slide

  41. Smaller Goals
    •Sane keyword arguments (?!!?!)
    •Pattern Matching
    •Deprecation of quirky features
    •Frozen string literals

    View full-size slide

  42. Ruby 3.0
    Redux

    View full-size slide

  43. Dictionary Definitions

    View full-size slide

  44. noun
    1. a precious stone consisting of
    corundum in colour varieties varying
    from deep crimson or purple to pale rose.
    2. a programming language optimised for
    programmer happiness

    View full-size slide

  45. number
    1. equivalent to the sum of one and
    two; one more than two; 3
    2. A mystical version rarely
    achieved by most software
    projects.

    View full-size slide

  46. adjective
    1. brought back, revived
    Emacs era redux
    2. (usually postpositive) (esp of
    an artistic work) presented in a new way
    Apocalypse Now Redux

    View full-size slide

  47. Ruby 3.0 is not
    a single
    magic release

    View full-size slide

  48. Ruby 3.0 is an idea

    View full-size slide

  49. Ruby follows SemVer

    View full-size slide

  50. Ruby 3 is going to be 3 times
    faster than Ruby 2.0

    View full-size slide

  51. Generational GC
    (Ruby 2.1)

    View full-size slide

  52. Incremental GC
    (Ruby 2.2)

    View full-size slide

  53. MJIT
    (Ruby 2.6)

    View full-size slide

  54. New AST library
    (Ruby 2.6)

    View full-size slide

  55. Deprecation of flip-flops
    (Ruby 2.6)

    View full-size slide

  56. Numbered block parameters

    View full-size slide

  57. numbers.map { Math.log2(@1) }

    View full-size slide

  58. foo.bar { @1 + @2 }

    View full-size slide

  59. h = Hash.new { @1[@2] = "Go Fish: #{@2}" }

    View full-size slide

  60. h = Hash.new { @1[@2] = "Go Fish: #{@2}" }

    View full-size slide

  61. https://bugs.ruby-lang.org/issues/15723

    View full-size slide

  62. Method reference operator

    View full-size slide

  63. [2, 4, 8, 16, 32].map { |n| Math.log2(n) }

    View full-size slide

  64. [2, 4, 8, 16, 32].map(&method(Math.log2))

    View full-size slide

  65. [2, 4, 8, 16, 32].map(&Math.:log2)

    View full-size slide

  66. [2, 4, 8, 16, 32].map { Math.log2($1) }

    View full-size slide

  67. Beginless range

    View full-size slide

  68. Beginless range

    View full-size slide

  69. Beginningless range

    View full-size slide

  70. items.where(price: ..20)

    View full-size slide

  71. Pattern Matching
    (https://bugs.ruby-lang.org/issues/14912)

    View full-size slide

  72. person = JSON.parse('{...}', symbolize_names: true)
    if person[:name] == ‘Alice’
    children = person[:children]
    if children.length == 1 && children[0][:name] == ‘Bob’
    p children[0][:age]
    end
    end

    View full-size slide

  73. case JSON.parse('{...}', symbolize_names: true)
    in {name: "Alice", children: [{name: "Bob", age: age}]}
    p age
    ...
    end

    View full-size slide

  74. Resources
    • https://speakerdeck.com/k_tsj/pattern-matching-new-
    feature-in-ruby-2-dot-7
    • https://medium.com/@baweaver/ruby-2-7-pattern-matching-
    first-impressions-cdb93c6246e6
    • https://medium.com/@baweaver/ruby-2-7-pattern-matching-
    destructuring-on-point-90f56aaf7b4e

    View full-size slide

  75. All those features are
    experimental
    and
    subject to change

    View full-size slide

  76. Compaction GC

    View full-size slide

  77. MJIT Tuning/optimizations

    View full-size slide

  78. Ruby 2.7.0-preview1 is out!

    View full-size slide

  79. Ruby 3.0
    (Current Status)

    View full-size slide

  80. Better Tools

    View full-size slide

  81. The bundling of Bundler
    (Ruby 2.6)

    View full-size slide

  82. Gemifying the Standard Library
    (ongoing progress)

    View full-size slide

  83. Default vs Bundled Gems

    View full-size slide

  84. Default Gems
    • Bundler
    • RubyGems
    • date
    • irb
    • json
    • …

    View full-size slide

  85. Bundled Gems
    • minitest
    • did_you_mean
    • rake
    • …

    View full-size slide

  86. irb
    • New reline backend (portable replacement for readline)
    • Completion
    • Multi-line editing
    • Syntax-highlighting
    • Integration with RDoc

    View full-size slide

  87. RDoc
    • Redesigned documentation system
    • Twice as fast

    View full-size slide

  88. Only applies to certain
    benchmarks

    View full-size slide

  89. Ruby 2.6
    is 65% faster than
    Ruby 2.0

    View full-size slide

  90. 10% average speedup per
    release

    View full-size slide

  91. MJIT is the biggest hope for
    Ruby 3x3

    View full-size slide

  92. Developed outside the Ruby’s
    main repo

    View full-size slide

  93. https://github.com/ko1/ruby/tree/guild

    View full-size slide

  94. Work in progress ™

    View full-size slide

  95. Parallel Programming in Ruby 3 with
    Guilds
    (http://www.atdot.net/~ko1/activities/2018_rubyconf2018.pdf)

    View full-size slide

  96. Static Typing

    View full-size slide

  97. https://bugs.ruby-lang.org/issues/9999

    View full-size slide

  98. Native Support for Тype
    Signatures in Ruby 3.0

    View full-size slide

  99. With a twist…

    View full-size slide

  100. Dedicated Ruby interface files
    (.rbi)

    View full-size slide

  101. class Person
    @name: String
    @contacts: Array
    def initialize: (name: String) -> any
    def name: -> String
    def contacts: -> Array
    def guess_country: -> (String | nil)
    end

    View full-size slide

  102. https://github.com/soutaro/steep

    View full-size slide

  103. Type Signatures for Ruby
    Core
    (https://github.com/ruby/ruby-signature)

    View full-size slide

  104. Rakia
    Connecting People

    View full-size slide

  105. Open Questions
    • Is Steep becoming part of the Standard Library?
    • How is Sorbet going to make use of its type annotations?
    • Typing applications

    View full-size slide

  106. Built-in Type Inference
    Checker

    View full-size slide

  107. def foo(x)
    if x > 10
    x.to_s
    else
    x.boo()
    x + 42
    end
    end
    foo(42)

    View full-size slide

  108. $ exe/type-profiler test.rb
    test.rb:6: [error] undefined method: Integer#boo
    test.rb:7: [error] failed to resolve overload: Integer#+
    Object#foo :: (Integer) -> String

    View full-size slide

  109. Resources
    • https://www.slideshare.net/mametter/a-typelevel-ruby-
    interpreter-for-testing-and-understanding
    • https://github.com/mame/ruby-type-profiler

    View full-size slide

  110. Sane Keyword Arguments

    View full-size slide

  111. https://bugs.ruby-lang.org/issues/14183

    View full-size slide

  112. # The following calls pass keyword arguments
    foo(..., key: val)
    foo(..., **hsh)
    foo(..., key: val, **hsh)

    View full-size slide

  113. # The following calls pass **normal** arguments
    foo(..., {key: val})
    foo(..., hsh)
    foo(..., {key: val, **hsh})

    View full-size slide

  114. Breaking change!!!

    View full-size slide

  115. Migration warning in
    Ruby 2.7

    View full-size slide

  116. What’s not in Ruby 3.0?

    View full-size slide

  117. Stream processing

    View full-size slide

  118. Frozen string literals

    View full-size slide

  119. Deprecation of autoload

    View full-size slide

  120. https://github.com/fxn/zeitwerk

    View full-size slide

  121. Deprecation of backticks
    (`some-command`)

    View full-size slide

  122. Deprecation of character literals
    (?x)

    View full-size slide

  123. • Ruby 2.7 will be the final release in the 2.x series

    • Ruby 3.0 is scheduled to land in 2020

    • Ruby 2.7 will serve as a preview for many of the key features in Ruby 3.0

    • Static typing and Guilds are the biggest changes coming to Ruby 3.0

    • Keyword argument overhaul is going to be a breaking change
    • The migration path from Ruby 2.x to 3.x should be very smooth

    View full-size slide

  124. Community Impact

    View full-size slide

  125. Community Contributed Features
    • UTF-8
    • Enumerator
    • Generational GC
    • Keyword Arguments
    • JIT
    • Concurrency

    View full-size slide

  126. Community Contributions
    • Rake
    • Bundler
    • Documentation & Tutorials
    • A ton of amazing libraries
    • Rails
    • …

    View full-size slide

  127. Real Namespaces
    (https://bugs.ruby-lang.org/issues/14982)

    View full-size slide

  128. Спасибо!
    twitter: @bbatsov
    github: @bbatsov
    https://metaredux.com
    https://emacsredux.com
    Saint P RubyConf 2019
    Saint Petersburg,
    Russia
    01.06.2019

    View full-size slide