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

Ruby 4.0: To Infinity and Beyond (RubyConf Kenya 2017)

Ruby 4.0: To Infinity and Beyond (RubyConf Kenya 2017)

Slide deck from my presentation at RubyConf Kenya 2017.

Bozhidar Batsov

June 11, 2017
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. View Slide

  2. Hello!

    View Slide

  3. Божидар

    View Slide

  4. View Slide

  5. View Slide

  6. Ruby 4.0:
    To INFINITY
    and Beyound
    by Bozhidar Batsov

    View Slide

  7. View Slide

  8. Not on Ruby’s Core
    Team

    View Slide

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

    View Slide

  10. Ruby is now mature

    View Slide

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

    View Slide

  12. View Slide

  13. The track record
    of
    recent Ruby innovation

    View Slide

  14. Ruby != MRI

    View Slide

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

    View Slide

  16. Ruby 2.0

    View Slide

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

    View Slide

  18. Ruby 2.1

    View Slide

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

    View Slide

  20. Ruby 2.2

    View Slide

  21. Nada

    View Slide

  22. Ruby 2.3

    View Slide

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

    View Slide

  24. Ruby 2.4

    View Slide

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

    View Slide

  26. Ruby 2.5?

    View Slide

  27. Java innovates
    more!

    View Slide

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

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

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

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

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

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

  34. View Slide

  35. What about Ruby 3.0?

    View Slide

  36. Little is known about
    it…

    View Slide

  37. Optional static
    typing?
    rejected

    View Slide

  38. Duck inference?

    View Slide

  39. Better support for
    concurrent & parallel
    programming

    View Slide

  40. View Slide

  41. 3 times faster
    performance?

    View Slide

  42. Getting rid of some
    quirky features?

    View Slide

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

    View Slide

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

    View Slide

  45. View Slide

  46. Ruby 4.0

    View Slide

  47. Codename Buzz

    View Slide

  48. Ruby 4x4

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  52. Ruby 4.0,
    the language

    View Slide

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

    View Slide

  54. Design principle #1

    View Slide

  55. Continue to optimize
    for happiness

    View Slide

  56. Add some useful new
    features

    View Slide

  57. Immutable data
    structures

    View Slide

  58. vector

    View Slide

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

    View Slide

  60. immutable hash

    View Slide

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

    View Slide

  62. immutable set

    View Slide

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

    View Slide

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

    View Slide

  65. Static typing and
    runtime contracts

    View Slide

  66. Inspired by RDL

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  70. Better concurrency
    APIs

    View Slide

  71. Inspired by
    concurrent-ruby

    View Slide

  72. CSP

    View Slide

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

    View Slide

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

  75. Design principle #2

    View Slide

  76. Simplicity

    View Slide

  77. Simplicity is the
    ultimate
    sophistication.

    View Slide

  78. Less is more

    View Slide

  79. Simplicity
    leads to
    happiness.

    View Slide

  80. Let’s drop some stuff

    View Slide

  81. Let’s drop some
    useless
    stuff

    View Slide

  82. for loops

    View Slide

  83. for name in names
    puts name
    end

    View Slide

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

    View Slide

  85. BEGIN & END

    View Slide

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

    View Slide

  87. puts 'Bye!'
    puts 'Starting...'
    puts 'Processing...'

    View Slide

  88. Kernel#at_exit,
    anyone?

    View Slide

  89. flip-flops

    View Slide

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

    View Slide

  91. block comments

    View Slide

  92. =begin
    comment line
    another comment line
    =end

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  96. Character literals

    View Slide

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

    View Slide

  98. $SAFE

    View Slide

  99. Let’s drop some
    redundant
    stuff

    View Slide

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

    View Slide

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

    View Slide

  102. core library method
    aliases

    View Slide

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

    View Slide

  104. Where is filter?

    View Slide

  105. map
    reduce
    find
    filter
    format
    length
    raise

    View Slide

  106. procs

    View Slide

  107. No arity check

    View Slide

  108. Non-local return

    View Slide

  109. Do we really need
    them?

    View Slide

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

    View Slide

  111. View Slide

  112. Single-quoted string
    literals

    View Slide

  113. View Slide

  114. A ton of obscure %-
    something literals

    View Slide

  115. %s, %x, %w, %W, %,
    %i

    View Slide

  116. %r, %q, %Q

    View Slide

  117. So excited to be here!

    View Slide

  118. puts "Hello, Nairobi!"
    puts "Hello, Nairobi!"
    puts "Hello, Nairobi!"

    View Slide

  119. for i in 1..3
    puts "Hello, Nairobi!"
    end

    View Slide

  120. 3.times do
    puts "Hello, Nairobi!"
    end

    View Slide

  121. 3.times do
    puts %(Hello, Nairobi!)
    end

    View Slide

  122. 3.times do
    puts %Q(Hello, Nairobi!)
    end

    View Slide

  123. 3.times do
    puts 'Hello, Nairobi!'
    end

    View Slide

  124. 3.times do
    puts %q(Hello, Nairobi!)
    end

    View Slide

  125. View Slide

  126. View Slide

  127. Are all those options
    worth our while?

    View Slide

  128. View Slide

  129. Let’s fix some stuff!

    View Slide

  130. and & or have the
    same precedence

    View Slide

  131. So many nils floating
    around

    View Slide

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

    View Slide

  133. Mutable strings

    View Slide

  134. Even JavaScript got
    this right…

    View Slide

  135. Reassignable
    constants

    View Slide

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

  137. View Slide

  138. Class variables

    View Slide

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

  140. Poorly named
    methods

    View Slide

  141. Kernel#puts

    View Slide

  142. Kernel#println,
    anyone?

    View Slide

  143. Kernel#print

    View Slide

  144. defined?

    View Slide

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

    View Slide

  146. View Slide

  147. Enumerable#include?

    View Slide

  148. Enumerable#includes?

    View Slide

  149. Kernel#%

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  155. Perl-style global
    variables

    View Slide

  156. $:

    View Slide

  157. $LOAD_PATH

    View Slide

  158. $;

    View Slide

  159. $FIELD_SEPARATOR

    View Slide

  160. $*

    View Slide

  161. $ARGV

    View Slide

  162. JRuby defines the
    English aliases by
    default

    View Slide

  163. Ruby 4.0 will do this
    as well!

    View Slide

  164. WTF? Global
    variables?

    View Slide

  165. View Slide

  166. Even Java doesn’t
    have globals…

    View Slide

  167. The future of the
    standard library

    View Slide

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

    View Slide

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

    View Slide

  170. Horrible APIs

    View Slide

  171. net/http anyone?

    View Slide

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

    View Slide

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

    View Slide

  174. View Slide

  175. View Slide

  176. View Slide

  177. View Slide

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

    View Slide

  179. 2. Remove everything
    outdated/obscure

    View Slide

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

    View Slide

  181. Wait, there’s more!

    View Slide

  182. Formal language
    specification and
    compatibility test suite

    View Slide

  183. Roadmaps for future
    Ruby releases

    View Slide

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

    View Slide

  185. Epilogue

    View Slide

  186. When will Ruby 4 be
    released?

    View Slide

  187. Ruby 4.0 will likely
    never happen

    View Slide

  188. View Slide

  189. Ruby 4.0 is already
    here!

    View Slide

  190. Crystal

    View Slide

  191. Clojure

    View Slide

  192. Elixir

    View Slide

  193. Scala

    View Slide

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

    View Slide

  195. Felina

    View Slide

  196. One more thing…

    View Slide

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

    View Slide

  198. –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

  199. File tickets

    View Slide

  200. Send patches

    View Slide

  201. Blog about the issues

    View Slide

  202. Speak about the
    issues

    View Slide

  203. Let’s make Ruby
    better together!

    View Slide

  204. Ruby
    Ruby

    View Slide

  205. Epilogue
    twitter: @bbatsov
    github: @bbatsov
    http//batsov.com
    http://emacsredux.com
    RubyConf Kenya
    Nairobi,
    Kenya
    09.06.2017

    View Slide