$30 off During Our Annual Pro Sale. View Details »

Ruby 4.0: To Infinity and Beyond (RubyConf.by 2017)

Ruby 4.0: To Infinity and Beyond (RubyConf.by 2017)

Slide deck from my RubyConf.by 2017 presentation

Bozhidar Batsov

April 02, 2017
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. View Slide

  2. Прывітанне!

    View Slide

  3. Божидар

    View Slide

  4. Bozhidar

    View Slide

  5. Bozho
    cool

    View Slide

  6. Bozo
    not cool

    View Slide

  7. Bug
    cool

    View Slide

  8. View Slide

  9. View Slide

  10. bbatsov

    View Slide

  11. Ruby & Rails
    style guides

    View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. Our Mission

    View Slide

  24. Find the best remote
    freelance jobs

    View Slide

  25. For the best
    freelancers

    View Slide

  26. And have them work
    on their own terms…

    View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. https://www.toptal.com/talent/apply

    View Slide

  33. 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. Ruby 4.0:
    To INFINITY
    and Beyound
    by Bozhidar Batsov

    View Slide

  45. View Slide

  46. Not on Ruby’s Core
    Team

    View Slide

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

    View Slide

  48. Ruby is now mature

    View Slide

  49. Build the things your
    users need, instead of
    the things they want.

    View Slide

  50. View Slide

  51. The track record
    of
    recent Ruby innovation

    View Slide

  52. Ruby != MRI

    View Slide

  53. 3.times do
    puts "Ruby Rocks!"
    end

    View Slide

  54. Ruby 2.0

    View Slide

  55. • keyword arguments
    • %i
    • UTF-8 is now the default source file encoding
    • Refinements (experimental feature)

    View Slide

  56. Ruby 2.1

    View Slide

  57. • Rational/Complex Literal
    • defs return value
    • Refinements are no longer experimental
    feature

    View Slide

  58. Ruby 2.2

    View Slide

  59. Nada

    View Slide

  60. Ruby 2.3

    View Slide

  61. • frozen string literals pragma
    • safe navigation operator (&.)
    • squiggly heredocs (<<~)

    View Slide

  62. Ruby 2.4

    View Slide

  63. • Unify Fixnum and Bignum into Integer
    • Support Unicode case mappings

    View Slide

  64. Ruby 2.5?

    View Slide

  65. Java innovates
    more!

    View Slide

  66. Ruby 2.2 includes many new features and
    improvements for the increasingly diverse and
    expanding demands for Ruby.
    For example, Ruby’s Garbage Collector is now able to
    collect Symbol type objects. This reduces memory
    usage of Symbols; because GC was previously unable
    to collect them before 2.2. Since Rails 5.0 will require
    Symbol GC, it will support only Ruby 2.2 or later.
    (See Rails 4.2 release post for details.)
    Also, a reduced pause time thanks to the new
    Incremental Garbage Collector will be helpful for
    running Rails applications. Recent developments
    mentioned on the Rails blog suggest that Rails 5.0
    will take advantage of Incremental GC as well as
    Symbol GC.

    View Slide

  67. Ruby 2.2 includes many new features and
    improvements for the increasingly diverse and
    expanding demands for Ruby.
    For example, Ruby’s Garbage Collector is now able to
    collect Symbol type objects. This reduces memory
    usage of Symbols; because GC was previously unable
    to collect them before 2.2. Since Rails 5.0 will require
    Symbol GC, it will support only Ruby 2.2 or later.
    (See Rails 4.2 release post for details.)
    Also, a reduced pause time thanks to the new
    Incremental Garbage Collector will be helpful for
    running Rails applications. Recent developments
    mentioned on the Rails blog suggest that Rails 5.0
    will take advantage of Incremental GC as well as
    Symbol GC.

    View Slide

  68. Ruby 2.2 includes many new features and
    improvements for the increasingly diverse and
    expanding demands for Ruby.
    For example, Ruby’s Garbage Collector is now able to
    collect Symbol type objects. This reduces memory
    usage of Symbols; because GC was previously unable
    to collect them before 2.2. Since Rails 5.0 will require
    Symbol GC, it will support only Ruby 2.2 or later.
    (See Rails 4.2 release post for details.)
    Also, a reduced pause time thanks to the new
    Incremental Garbage Collector will be helpful for
    running Rails applications. Recent developments
    mentioned on the Rails blog suggest that Rails 5.0
    will take advantage of Incremental GC as well as
    Symbol GC.

    View Slide

  69. Ruby 2.2 includes many new features and
    improvements for the increasingly diverse and
    expanding demands for Ruby.
    For example, Ruby’s Garbage Collector is now able to
    collect Symbol type objects. This reduces memory
    usage of Symbols; because GC was previously unable
    to collect them before 2.2. Since Rails 5.0 will require
    Symbol GC, it will support only Ruby 2.2 or later.
    (See Rails 4.2 release post for details.)
    Also, a reduced pause time thanks to the new
    Incremental Garbage Collector will be helpful for
    running Rails applications. Recent developments
    mentioned on the Rails blog suggest that Rails 5.0
    will take advantage of Incremental GC as well as
    Symbol GC.

    View Slide

  70. Ruby 2.2 includes many new features and
    improvements for the increasingly diverse and
    expanding demands for Ruby.
    For example, Ruby’s Garbage Collector is now able to
    collect Symbol type objects. This reduces memory
    usage of Symbols; because GC was previously unable
    to collect them before 2.2. Since Rails 5.0 will require
    Symbol GC, it will support only Ruby 2.2 or later.
    (See Rails 4.2 release post for details.)
    Also, a reduced pause time thanks to the new
    Incremental Garbage Collector will be helpful for
    running Rails applications. Recent developments
    mentioned on the Rails blog suggest that Rails 5.0
    will take advantage of Incremental GC as well as
    Symbol GC.

    View Slide

  71. Ruby 2.2 includes many new features and
    improvements for the increasingly diverse and
    expanding demands for Ruby.
    For example, Ruby’s Garbage Collector is now able to
    collect Symbol type objects. This reduces memory
    usage of Symbols; because GC was previously unable
    to collect them before 2.2. Since Rails 5.0 will require
    Symbol GC, it will support only Ruby 2.2 or later.
    (See Rails 4.2 release post for details.)
    Also, a reduced pause time thanks to the new
    Incremental Garbage Collector will be helpful for
    running Rails applications. Recent developments
    mentioned on the Rails blog suggest that Rails 5.0
    will take advantage of Incremental GC as well as
    Symbol GC.

    View Slide

  72. View Slide

  73. What about Ruby 3.0?

    View Slide

  74. Little is known about
    it…

    View Slide

  75. Optional static
    typing?
    rejected

    View Slide

  76. Duck inference?

    View Slide

  77. Better support for
    concurrent & parallel
    programming

    View Slide

  78. View Slide

  79. 3 times faster
    performance?

    View Slide

  80. Getting rid of some
    quirky features?

    View Slide

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

    View Slide

  82. And what about the
    Perl 6 mistakes?
    — Bozhidar

    View Slide

  83. View Slide

  84. Ruby 4.0

    View Slide

  85. Codename Buzz

    View Slide

  86. Ruby 4x4

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  90. Ruby 4 is going to be
    slower than JRuby 9k!

    View Slide

  91. Ruby 4.0,
    the language

    View Slide

  92. Ruby 4.0,
    the language
    (and maybe the Standard Library)

    View Slide

  93. Design principle #1

    View Slide

  94. Continue to optimize
    for happiness

    View Slide

  95. Add some useful new
    features

    View Slide

  96. Immutable data
    structures

    View Slide

  97. vector

    View Slide

  98. v = @[1, 2, 3]

    View Slide

  99. immutable hash

    View Slide

  100. m = @{one: 1, two: 2}

    View Slide

  101. immutable set

    View Slide

  102. s = @${1, 2, 3}

    View Slide

  103. s = ${1, 2, 3}

    View Slide

  104. Static typing and
    runtime contracts

    View Slide

  105. Inspired by RDL

    View Slide

  106. type '(Fixnum, Fixnum) -> String'
    def m(x, y) ... end

    View Slide

  107. pre { |x| x > 0 }
    post { |r,x| r > 0 }
    def sqrt(x)
    # return the square root of x
    end

    View Slide

  108. type '(Float x {{ x>=0 }}) -> Float y
    {{ y>=0 }}'
    def sqrt(x)
    # return the square root of x
    end

    View Slide

  109. Better concurrency
    APIs

    View Slide

  110. Inspired by
    concurrent-ruby

    View Slide

  111. CSP

    View Slide

  112. messages = Concurrent::Channel.new
    Concurrent::Channel.go do
    messages.put 'ping'
    end
    msg = messages.take
    puts msg

    View Slide

  113. def sum(a, c)
    sum = a.reduce(0, &:+)
    c << sum # `<<` is an alias for `put` or `send`
    end
    a = [7, 2, 8, -9, 4, 0]
    l = a.length / 2
    c = Concurrent::Channel.new
    Concurrent::Channel.go { sum(a[-l, l], c) }
    Concurrent::Channel.go { sum(a[0, l], c) }
    x, y = ~c, ~c # `~` is an alias for `take` or `receive`
    puts [x, y, x+y].join(' ')

    View Slide

  114. Design principle #2

    View Slide

  115. Simplicity

    View Slide

  116. Simplicity is the
    ultimate
    sophistication.

    View Slide

  117. Less is more

    View Slide

  118. Simplicity
    leads to
    happiness.

    View Slide

  119. Let’s drop some stuff

    View Slide

  120. Let’s drop some
    useless
    stuff

    View Slide

  121. for loops

    View Slide

  122. for name in names
    puts name
    end

    View Slide

  123. names.each do |name|
    puts name
    end

    View Slide

  124. BEGIN & END

    View Slide

  125. END {
    puts 'Bye!'
    }
    puts 'Processing...'
    BEGIN {
    puts 'Starting...'
    }

    View Slide

  126. puts 'Bye!'
    puts 'Starting...'
    puts 'Processing...'

    View Slide

  127. Kernel#at_exit,
    anyone?

    View Slide

  128. flip-flops

    View Slide

  129. DATA.each_line do |line|
    print(line) if (line =~ /begin/)..(line =~ /end/)
    end

    View Slide

  130. block comments

    View Slide

  131. =begin
    comment line
    another comment line
    =end

    View Slide

  132. Must be placed at the
    very beginning of a line

    View Slide

  133. class SomeClass
    =begin
    This is a top comment.
    Or is it?
    =end
    def some_method
    end
    end

    View Slide

  134. class SomeClass
    =begin
    This is a top comment.
    Or is it?
    =end
    def some_method
    end
    end

    View Slide

  135. Character literals

    View Slide

  136. pry(main)> ?a
    => "a"

    View Slide

  137. $SAFE

    View Slide

  138. Let’s drop some
    redundant
    stuff

    View Slide

  139. There’s more than
    one way to do it

    View Slide

  140. (There are way too
    many ways to do it)

    View Slide

  141. core library method
    aliases

    View Slide

  142. collect => map
    inject => reduce
    detect => find
    select => find_all
    sprintf => format
    length => size
    raise => fail

    View Slide

  143. Where is filter?

    View Slide

  144. map
    reduce
    find
    filter
    format
    length
    raise

    View Slide

  145. procs

    View Slide

  146. No arity check

    View Slide

  147. Non-local return

    View Slide

  148. Do we really need
    them?

    View Slide

  149. So many languages are
    getting by just fine
    with only lambdas…

    View Slide

  150. View Slide

  151. Single-quoted string
    literals

    View Slide

  152. View Slide

  153. A ton of obscure %-
    something literals

    View Slide

  154. %s, %x, %w, %W,
    %r, %q, %Q, %, %i

    View Slide

  155. So excited to be here!

    View Slide

  156. puts "Hello, Minsk!"
    puts "Hello, Minsk!"
    puts "Hello, Minsk!"

    View Slide

  157. for i in 1..3
    puts "Hello, Minsk!"
    end

    View Slide

  158. 3.times do
    puts "Hello, Minsk!"
    end

    View Slide

  159. 3.times do
    puts %(Hello, Minsk!)
    end

    View Slide

  160. 3.times do
    puts %Q(Hello, Minsk!)
    end

    View Slide

  161. 3.times do
    puts 'Hello, Minsk!'
    end

    View Slide

  162. 3.times do
    puts %q(Hello, Minsk!)
    end

    View Slide

  163. View Slide

  164. View Slide

  165. Are all those options
    worth our while?

    View Slide

  166. View Slide

  167. Let’s fix some stuff!

    View Slide

  168. and & or have the
    same precedence

    View Slide

  169. So many nils floating
    around

    View Slide

  170. pry(main)> "TOP".upcase
    => "TOP"
    pry(main)> "TOP".upcase!
    => nil

    View Slide

  171. Mutable strings

    View Slide

  172. Even JavaScript got
    this right…

    View Slide

  173. Reassignable
    constants

    View Slide

  174. pry(main)> A = 5
    => 5
    pry(main)> A = 6
    (pry):39: warning: already initialized constant A
    (pry):38: warning: previous definition of A was here
    => 6
    pry(main)> Class = 3
    (pry):40: warning: already initialized constant Class
    => 3
    pry(main)> Class
    => 3

    View Slide

  175. View Slide

  176. Class variables

    View Slide

  177. class Parent
    @@class_var = 'parent'
    def self.print_class_var
    puts @@class_var
    end
    end
    class Child < Parent
    @@class_var = 'child'
    end
    Parent.print_class_var # => will print "child"

    View Slide

  178. Poorly named
    methods

    View Slide

  179. Kernel#puts

    View Slide

  180. Kernel#println,
    anyone?

    View Slide

  181. Kernel#print

    View Slide

  182. defined?

    View Slide

  183. [1] pry(main)> defined? 10
    => "expression"
    [2] pry(main)> defined? Test
    => nil
    [3] pry(main)> defined? TrueClass
    => "constant"

    View Slide

  184. View Slide

  185. Enumerable#include?

    View Slide

  186. Enumerable#includes?

    View Slide

  187. Kernel#%

    View Slide

  188. '%d %d' % [20, 10]

    View Slide

  189. sprintf('%d %d', 20, 10)

    View Slide

  190. sprintf(
    '%{first} %{second}',
    first: 20, second: 10
    )

    View Slide

  191. format('%{first} %{second}',
    first: 20, second: 10)

    View Slide

  192. In what universe would
    you prefer Kernel#%
    over Kernel#format???

    View Slide

  193. Perl-style global
    variables

    View Slide

  194. $:

    View Slide

  195. $LOAD_PATH

    View Slide

  196. $;

    View Slide

  197. $FIELD_SEPARATOR

    View Slide

  198. $*

    View Slide

  199. $ARGV

    View Slide

  200. JRuby defines the
    English aliases by
    default

    View Slide

  201. Ruby 4.0 will do this
    as well!

    View Slide

  202. WTF? Global
    variables?

    View Slide

  203. View Slide

  204. Even Java doesn’t
    have globals…

    View Slide

  205. The future of the
    standard library

    View Slide

  206. The Ruby Stdlib is a
    Ghetto
    http://www.mikeperham.com/2010/11/22/the-ruby-stdlib-
    is-a-ghetto/

    View Slide

  207. A ton of legacy code
    (often last updated
    2000-2003)

    View Slide

  208. Horrible APIs

    View Slide

  209. net/http anyone?

    View Slide

  210. The Kill List
    • Net::*
    • DRb
    • REXML
    • RSS
    • Rinda
    • WEBrick
    • XML

    View Slide

  211. What are the parts of the
    standard library you
    dislike the most? Why so?

    View Slide

  212. View Slide

  213. View Slide

  214. View Slide

  215. View Slide

  216. 1. Move the important
    bits to the Core Library

    View Slide

  217. 2. Remove everything
    outdated/obscure

    View Slide

  218. 3. Leverage modern
    Ruby features in the
    Standard Library

    View Slide

  219. Wait, there’s more!

    View Slide

  220. Formal language
    specification and
    compatibility test suite

    View Slide

  221. Roadmaps for future
    Ruby releases

    View Slide

  222. We’ll adopt the Rubinius
    VM and make it 100%
    compatible with MRI

    View Slide

  223. Epilogue
    1/2

    View Slide

  224. When will Ruby 4 be
    released?

    View Slide

  225. Ruby 4.0 will likely
    never happen

    View Slide

  226. View Slide

  227. Ruby 4.0 is already
    here!

    View Slide

  228. Crystal

    View Slide

  229. Clojure

    View Slide

  230. Elixir

    View Slide

  231. Scala

    View Slide

  232. –William Gibson
    “Тhe future is already here it's just not
    evenly distributed.”

    View Slide

  233. Felina

    View Slide

  234. One more thing…

    View Slide

  235. Stewardship:
    The Sobering Parts
    https://www.youtube.com/watch?v=2y5Pv4yN0b0

    View Slide

  236. –Zach Tellman
    There has been a consistent migratory
    pattern from Ruby to node.js to Go, Rust,
    and Elixir. At first, each community is
    defined by its potential. But as that potential
    is realized, the community begins to be
    defined by its compromises. That change is
    felt most keenly by the people who were
    there first, who remember what it was like
    when anything seemed possible. They feel
    fenced in and so they move on, in search of
    their golden city..”

    View Slide

  237. File tickets

    View Slide

  238. Send patches

    View Slide

  239. Blog about the issues

    View Slide

  240. Speak about the
    issues

    View Slide

  241. Let’s make Ruby
    better together!

    View Slide

  242. Ruby
    Ruby

    View Slide

  243. Epilogue
    twitter: @bbatsov
    github: @bbatsov
    http//batsov.com
    http://emacsredux.com
    RubyConf.by
    Minsk,
    Belarus
    02.04.2017

    View Slide