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

Ruby 3.0 Redux (Pivorak 4.0)

Ruby 3.0 Redux (Pivorak 4.0)

Bozhidar Batsov

October 18, 2019
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. View Slide

  2. Привiт!

    View Slide

  3. Божидар

    View Slide

  4. Божо
    cool

    View Slide

  5. Bozhidar

    View Slide

  6. Bozhidar

    View Slide

  7. Божи дар

    View Slide

  8. Божий дар

    View Slide

  9. View Slide

  10. Sofia, Bulgaria
    Sofia, Bulgaria

    View Slide

  11. View Slide

  12. bbatsov

    View Slide

  13. Ruby & Rails
    style guides

    View Slide

  14. •rubystyle.guide
    •rails.rubystyle.guide
    •rspec.rubystyle.guide
    •minitest.rubystyle.guide
    •blog.rubystyle.guide

    View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. rubocop-minitest

    View Slide

  19. rubocop-rake

    View Slide

  20. View Slide

  21. emacsredux.com

    View Slide

  22. metaredux.com

    View Slide

  23. #7 on the list of top white
    hackers in Bulgaria!

    View Slide

  24. View Slide

  25. Божидар Батсов

    View Slide

  26. стацковарфлоу

    View Slide

  27. Expert in cyber security

    View Slide

  28. Expert in the following
    programming languages:
    Unix, Emacs, Perl and Ruby

    View Slide

  29. The Don Juan of IT in
    Bulgaria

    View Slide

  30. View Slide

  31. slide intentionally
    left blank

    View Slide

  32. View Slide

  33. View Slide

  34. Bulgarian Cheese

    View Slide

  35. Болгарка

    View Slide

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

    View Slide

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

    View Slide

  38. Банско

    View Slide

  39. Луканка

    View Slide

  40. Rakia
    Connecting People

    View Slide

  41. Shopska Salad
    (use only with Rakia)

    View Slide

  42. View Slide

  43. View Slide

  44. Bulgarian politics are shit
    wrapped in cellophane.

    View Slide

  45. I’m never happy about a small
    pig and a new boss.

    View Slide

  46. To mess with my deputy is like
    sitting butt naked on a hedgehog.

    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. The most beautiful city in
    Ukraine

    View Slide

  56. View Slide

  57. То є Львів, мій колєґа, про нього різне кажуть:

    Приезжим из востока Криївку тут покажуть.

    То є Львів, моє місто, не з простого тіста,

    Ліплений роками – друзями й ворогами.

    То є Львів старенький, мудрий, сивий дядько,

    Кожному залишить кавалочок на згадку.

    То є Львів "Бонжорно!", Неаполь і Ліворно,

    По-галицьки говорять, наші в них погоду
    роблять.

    View Slide

  58. То є Львів, шановні, вбирайте шлюбні сподні,

    Краватку, маринарку і "вйо!" по Стрийськім парку.

    То є Львів чудовий, вуйко ґонуровий,

    Я тішуся, шо з вами ходжу цими вулицями.

    То є Львів старенький, мудрий, сивий дядько,

    Кожному залишить кавалочок на згадку.

    То є Львів "Бонжорно!", Неаполь і Ліворно,

    По-галицьки говорять, наші в них погоду роблять.

    То є Львів, то Львів...

    View Slide

  59. View Slide

  60. View Slide

  61. View Slide

  62. Not on Ruby’s Core Team

    View Slide

  63. Matz
    on
    Ruby

    View Slide

  64. Language Maturity

    View Slide

  65. The Ruby Community

    View Slide

  66. Ruby is not dying

    View Slide

  67. View Slide

  68. View Slide

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

    View Slide

  70. We have to keep moving
    forward.
    — Matz

    View Slide

  71. Backwards Compatibility

    View Slide

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

    View Slide

  73. Victim of the Hype Cycle

    View Slide

  74. View Slide

  75. Rails Mania (2008)

    View Slide

  76. Ruby Today

    View Slide

  77. Ruby Today

    View Slide

  78. 2025

    View Slide

  79. Matz’s Retirement

    View Slide

  80. View Slide

  81. Ruby 4

    View Slide

  82. Ruby 4x4

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  86. View Slide

  87. What about Ruby 3?

    View Slide

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

    View Slide

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

    View Slide

  90. Optional static typing?

    View Slide

  91. Duck inference?

    View Slide

  92. Actors?

    View Slide

  93. Stream based model?

    View Slide

  94. Ownership based model?

    View Slide

  95. Guilds?

    View Slide

  96. 3 times faster performance?

    View Slide

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

    View Slide

  98. View Slide

  99. Ruby 3.0
    Redux

    View Slide

  100. Dictionary Definitions

    View Slide

  101. Ruby

    View Slide

  102. 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

  103. 3

    View Slide

  104. 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

  105. Redux

    View Slide

  106. 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

  107. View Slide

  108. Ruby 3.0 is not
    a single
    magic release

    View Slide

  109. Ruby 3.0 is an idea

    View Slide

  110. View Slide

  111. Ruby follows SemVer

    View Slide

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

    View Slide

  113. Generational GC
    (Ruby 2.1)

    View Slide

  114. Incremental GC
    (Ruby 2.2)

    View Slide

  115. MJIT
    (Ruby 2.6)

    View Slide

  116. New AST library
    (Ruby 2.6)

    View Slide

  117. Deprecation of flip-flops
    (Ruby 2.6)

    View Slide

  118. Ruby 2.7

    View Slide

  119. Numbered block parameters

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  124. View Slide

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

    View Slide

  126. numbers.map { Math.log2(_1) }

    View Slide

  127. View Slide

  128. Method reference operator

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  132. [2, 4, 8, 16, 32].map { Math.log2(_1) }

    View Slide

  133. Beginless range

    View Slide

  134. Beginless range

    View Slide

  135. Beginningless range

    View Slide

  136. arr[..3]

    View Slide

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

    View Slide

  138. View Slide

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

    View Slide

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

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

    View Slide

  142. View Slide

  143. 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

  144. All those features are
    experimental
    and
    subject to change

    View Slide

  145. Deprecating $; and $,

    View Slide

  146. > $; = " "
    warning: non-nil $; will be deprecate
    => " "
    > "hello world!".split
    warning: $; is set to non-nil value
    => ["hello", "world!"]
    > $, = " "
    warning: non-nil $, will be deprecated
    => " "
    > ["hello", "world!"].join
    warning: non-nil $, will be deprecated
    => "hello world!"

    View Slide

  147. Compaction GC

    View Slide

  148. MJIT Tuning/optimizations

    View Slide

  149. flip-flops were finally
    deprecated!

    View Slide

  150. Then they were reinstated…

    View Slide

  151. View Slide

  152. Pipeline operator

    View Slide

  153. foo()
    .bar(1, 2)
    .display

    View Slide

  154. foo()
    |> bar 1, 2
    |> display

    View Slide

  155. View Slide

  156. Added, contested and
    removed

    View Slide

  157. View Slide

  158. Ruby 2.7 is coming for
    Christmas!

    View Slide

  159. Ruby 3.0
    (Current Status)

    View Slide

  160. Better Tools

    View Slide

  161. RubyGems 3

    View Slide

  162. The bundling of Bundler
    (Ruby 2.6)

    View Slide

  163. Gemifying the Standard Library
    (ongoing progress)

    View Slide

  164. Default vs Bundled Gems

    View Slide

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

    View Slide

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

    View Slide

  167. stdgems.org

    View Slide

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

    View Slide

  169. View Slide

  170. RDoc
    • Redesigned documentation system
    • Twice as fast

    View Slide

  171. Ruby 3x3

    View Slide

  172. Only applies to certain
    benchmarks

    View Slide

  173. Ruby 2.6
    is 65% faster than
    Ruby 2.0

    View Slide

  174. View Slide

  175. 10% average speedup per
    release

    View Slide

  176. View Slide

  177. MJIT is the biggest hope for
    Ruby 3x3

    View Slide

  178. Guilds

    View Slide

  179. View Slide

  180. View Slide

  181. Developed outside the Ruby’s
    main repo

    View Slide

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

    View Slide

  183. Work in progress ™

    View Slide

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

    View Slide

  185. Static Typing

    View Slide

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

    View Slide

  187. View Slide

  188. Native Support for Тype
    Signatures in Ruby 3.0

    View Slide

  189. View Slide

  190. With a twist…

    View Slide

  191. Dedicated Ruby interface files
    (.rbi)

    View Slide

  192. Dedicated Ruby signature files
    (.rbs)

    View Slide

  193. 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

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

    View Slide

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

    View Slide

  196. Rakia
    Connecting People

    View Slide

  197. 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

  198. Built-in Type Inference
    Checker

    View Slide

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

    View Slide

  200. $ 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

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

    View Slide

  202. Sane Keyword Arguments

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  206. Breaking change!!!

    View Slide

  207. Migration warning in
    Ruby 2.7

    View Slide

  208. def a_method(k: 1)
    puts "k: #{k}"
    end
    a_method({k: 1})
    (irb):4: warning: The last argument is
    used as the keyword parameter
    (irb):1: warning: for `a_method'
    defined here
    => k: 1

    View Slide

  209. # To avoid the warning
    # and make it Ruby 3 compatible,
    # use the double splat operator
    a_method(**{k: 1})
    => k: 1

    View Slide

  210. What’s not in Ruby 3.0?

    View Slide

  211. Actors

    View Slide

  212. Stream processing

    View Slide

  213. Frozen string literals

    View Slide

  214. Deprecation of autoload

    View Slide

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

    View Slide

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

    View Slide

  217. Deprecation of character literals
    (?x)

    View Slide

  218. Summary

    View Slide

  219. • 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

  220. Community Impact

    View Slide

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

    View Slide

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

    View Slide

  223. View Slide

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

    View Slide

  225. View Slide

  226. Felina

    View Slide

  227. Дякую!
    twitter: @bbatsov
    github: @bbatsov
    https://metaredux.com
    https://emacsredux.com
    Pivorak 4.0
    Lviv,
    Ukraine
    18.10.2019

    View Slide