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 Slide

  2. View Slide

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

    View Slide

  4. Божидар

    View Slide

  5. Божо
    cool

    View Slide

  6. Bozhidar

    View Slide

  7. Bozhidar

    View Slide

  8. Bug
    cool

    View Slide

  9. Божи дар

    View Slide

  10. Божий дар

    View Slide

  11. View Slide

  12. @bbatsov

    View Slide

  13. Бацов

    View Slide

  14. Батсов

    View Slide

  15. Sofia, Bulgaria
    Sofia, Bulgaria

    View Slide

  16. View Slide

  17. View Slide

  18. Bulgarian Cheese

    View Slide

  19. Болгарка

    View Slide

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

    View Slide

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

    View Slide

  22. Банско

    View Slide

  23. Луканка

    View Slide

  24. Rakia
    Connecting People

    View Slide

  25. Shopska Salad
    (use only with Rakia)

    View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. bbatsov

    View Slide

  33. metaredux.com

    View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. View Slide

  42. View Slide

  43. View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. View Slide

  48. View Slide

  49. View Slide

  50. View Slide

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

    View Slide

  52. View Slide

  53. View Slide

  54. View Slide

  55. View Slide

  56. Not on Ruby’s Core Team

    View Slide

  57. Ruby & Rails
    style guides

    View Slide

  58. View Slide

  59. View Slide

  60. View Slide

  61. View Slide

  62. Matz
    on
    Ruby

    View Slide

  63. Language Maturity

    View Slide

  64. The Ruby Community

    View Slide

  65. Ruby is not dying

    View Slide

  66. View Slide

  67. View Slide

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

    View Slide

  69. We have to keep moving
    forward.
    — Matz

    View Slide

  70. Backwards Compatibility

    View Slide

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

    View Slide

  72. Victim of the Hype Cycle

    View Slide

  73. View Slide

  74. Rails Mania (2008)

    View Slide

  75. Ruby Today

    View Slide

  76. Ruby Today

    View Slide

  77. 2025

    View Slide

  78. Matz’s Retirement

    View Slide

  79. View Slide

  80. Ruby 4

    View Slide

  81. Ruby 4x4

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  85. View Slide

  86. What about Ruby 3?

    View Slide

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

    View Slide

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

    View Slide

  89. Optional static typing?

    View Slide

  90. Duck inference?

    View Slide

  91. Actors?

    View Slide

  92. Stream based model?

    View Slide

  93. Ownership based model?

    View Slide

  94. Guilds?

    View Slide

  95. 3 times faster performance?

    View Slide

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

    View Slide

  97. View Slide

  98. Ruby 3.0
    Redux

    View Slide

  99. Dictionary Definitions

    View Slide

  100. Ruby

    View Slide

  101. 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 Slide

  102. 3

    View Slide

  103. 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 Slide

  104. Redux

    View Slide

  105. 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 Slide

  106. View Slide

  107. Ruby 3.0 is not
    a single
    magic release

    View Slide

  108. Ruby 3.0 is an idea

    View Slide

  109. View Slide

  110. Ruby follows SemVer

    View Slide

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

    View Slide

  112. Generational GC
    (Ruby 2.1)

    View Slide

  113. Incremental GC
    (Ruby 2.2)

    View Slide

  114. MJIT
    (Ruby 2.6)

    View Slide

  115. New AST library
    (Ruby 2.6)

    View Slide

  116. Deprecation of flip-flops
    (Ruby 2.6)

    View Slide

  117. Ruby 2.7

    View Slide

  118. Numbered block parameters

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  123. View Slide

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

    View Slide

  125. Method reference operator

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  130. Beginless range

    View Slide

  131. Beginless range

    View Slide

  132. Beginningless range

    View Slide

  133. arr[..3]

    View Slide

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

    View Slide

  135. View Slide

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

    View Slide

  137. 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 Slide

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

    View Slide

  139. View Slide

  140. 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 Slide

  141. All those features are
    experimental
    and
    subject to change

    View Slide

  142. Compaction GC

    View Slide

  143. MJIT Tuning/optimizations

    View Slide

  144. Ruby 2.7.0-preview1 is out!

    View Slide

  145. Ruby 3.0
    (Current Status)

    View Slide

  146. Better Tools

    View Slide

  147. RubyGems 3

    View Slide

  148. The bundling of Bundler
    (Ruby 2.6)

    View Slide

  149. Gemifying the Standard Library
    (ongoing progress)

    View Slide

  150. Default vs Bundled Gems

    View Slide

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

    View Slide

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

    View Slide

  153. stdgems.org

    View Slide

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

    View Slide

  155. View Slide

  156. RDoc
    • Redesigned documentation system
    • Twice as fast

    View Slide

  157. Ruby 3x3

    View Slide

  158. Only applies to certain
    benchmarks

    View Slide

  159. Ruby 2.6
    is 65% faster than
    Ruby 2.0

    View Slide

  160. View Slide

  161. 10% average speedup per
    release

    View Slide

  162. View Slide

  163. MJIT is the biggest hope for
    Ruby 3x3

    View Slide

  164. Guilds

    View Slide

  165. View Slide

  166. View Slide

  167. Developed outside the Ruby’s
    main repo

    View Slide

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

    View Slide

  169. Work in progress ™

    View Slide

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

    View Slide

  171. Static Typing

    View Slide

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

    View Slide

  173. View Slide

  174. Native Support for Тype
    Signatures in Ruby 3.0

    View Slide

  175. View Slide

  176. With a twist…

    View Slide

  177. Dedicated Ruby interface files
    (.rbi)

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  181. Rakia
    Connecting People

    View Slide

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

    View Slide

  183. Built-in Type Inference
    Checker

    View Slide

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

    View Slide

  185. $ 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 Slide

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

    View Slide

  187. Sane Keyword Arguments

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  191. Breaking change!!!

    View Slide

  192. Migration warning in
    Ruby 2.7

    View Slide

  193. What’s not in Ruby 3.0?

    View Slide

  194. Actors

    View Slide

  195. Stream processing

    View Slide

  196. Frozen string literals

    View Slide

  197. Deprecation of autoload

    View Slide

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

    View Slide

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

    View Slide

  200. Deprecation of character literals
    (?x)

    View Slide

  201. Summary

    View Slide

  202. • 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 Slide

  203. Community Impact

    View Slide

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

    View Slide

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

    View Slide

  206. View Slide

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

    View Slide

  208. View Slide

  209. Felina

    View Slide

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

    View Slide