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

Ruby 4.0: To Infinity and Beyond (Athens Ruby Meetup)

Ruby 4.0: To Infinity and Beyond (Athens Ruby Meetup)

The slide deck from the presentation I gave at the Athens Ruby Meetup on 18.11.2016.

Bozhidar Batsov

November 22, 2016
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. View Slide

  2. Ờửλỷσπέρử

    View Slide

  3. Божидар

    View Slide

  4. View Slide

  5. Bozhidar

    View Slide

  6. Bozho
    cool

    View Slide

  7. Bozo
    not cool

    View Slide

  8. Bug
    cool

    View Slide

  9. View Slide

  10. View Slide

  11. bbatsov

    View Slide

  12. Ruby & Rails
    style guides

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

  24. View Slide

  25. View Slide

  26. View Slide

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

    View Slide

  28. View Slide

  29. Not on Ruby’s Core
    Team

    View Slide

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

    View Slide

  31. Ruby is now mature

    View Slide

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

    View Slide

  33. View Slide

  34. The track record
    of
    recent Ruby innovation

    View Slide

  35. Ruby != MRI

    View Slide

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

    View Slide

  37. Ruby 2.0

    View Slide

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

    View Slide

  39. Ruby 2.1

    View Slide

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

    View Slide

  41. Ruby 2.2

    View Slide

  42. Nada

    View Slide

  43. Ruby 2.3

    View Slide

  44. • frozen string literals pragma
    • safe navigation operator (&.)

    View Slide

  45. Ruby 2.4

    View Slide

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

    View Slide

  47. Java innovates
    more!

    View Slide

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

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

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

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

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

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

  54. View Slide

  55. What about Ruby 3.0?

    View Slide

  56. Little is known about
    it…

    View Slide

  57. Optional static
    typing?
    rejected

    View Slide

  58. Duck inference?

    View Slide

  59. Better support for
    concurrent & parallel
    programming

    View Slide

  60. View Slide

  61. 3 times faster
    performance?

    View Slide

  62. Getting rid of some
    quirky features?

    View Slide

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

    View Slide

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

    View Slide

  65. View Slide

  66. Ruby 4.0

    View Slide

  67. Codename Buzz

    View Slide

  68. Ruby 4x4

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  72. Ruby 4.0,
    the language

    View Slide

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

    View Slide

  74. Design principle #1

    View Slide

  75. Continue to optimize
    for happiness

    View Slide

  76. Add some useful new
    features

    View Slide

  77. Immutable data
    structures

    View Slide

  78. vector

    View Slide

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

    View Slide

  80. immutable hash

    View Slide

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

    View Slide

  82. immutable set

    View Slide

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

    View Slide

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

    View Slide

  85. Static typing and
    runtime contracts

    View Slide

  86. Inspired by RDL

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  90. Better concurrency
    APIs

    View Slide

  91. Inspired by
    concurrent-ruby

    View Slide

  92. CSP

    View Slide

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

    View Slide

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

  95. Design principle #2

    View Slide

  96. Simplicity

    View Slide

  97. Simplicity is the
    ultimate
    sophistication.

    View Slide

  98. Less is more

    View Slide

  99. Simplicity
    leads to
    happiness.

    View Slide

  100. Let’s drop some stuff

    View Slide

  101. Let’s drop some
    useless
    stuff

    View Slide

  102. for loops

    View Slide

  103. for name in names
    puts name
    end

    View Slide

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

    View Slide

  105. BEGIN & END

    View Slide

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

    View Slide

  107. puts 'Bye!'
    puts 'Starting...'
    puts 'Processing...'

    View Slide

  108. Kernel#at_exit,
    anyone?

    View Slide

  109. flip-flops

    View Slide

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

    View Slide

  111. block comments

    View Slide

  112. =begin
    comment line
    another comment line
    =end

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  116. Character literals

    View Slide

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

    View Slide

  118. Let’s drop some
    redundant
    stuff

    View Slide

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

    View Slide

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

    View Slide

  121. core library method
    aliases

    View Slide

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

    View Slide

  123. Where is filter?

    View Slide

  124. map
    reduce
    find
    filter
    format
    length
    raise

    View Slide

  125. procs

    View Slide

  126. No arity check

    View Slide

  127. Non-local return

    View Slide

  128. Do we really need
    them?

    View Slide

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

    View Slide

  130. View Slide

  131. Single-quoted string
    literals

    View Slide

  132. View Slide

  133. A ton of obscure %-
    something literals

    View Slide

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

    View Slide

  135. So excited to be here!

    View Slide

  136. puts "Hello, Athens!"
    puts "Hello, Athens!"
    puts "Hello, Athens!"

    View Slide

  137. for i in 1..3
    puts "Hello, Athens!"
    end

    View Slide

  138. 3.times do
    puts "Hello, Athens!"
    end

    View Slide

  139. 3.times do
    puts %(Hello, Athens!)
    end

    View Slide

  140. 3.times do
    puts %Q(Hello, Athens!)
    end

    View Slide

  141. 3.times do
    puts 'Hello, Athens!'
    end

    View Slide

  142. 3.times do
    puts %q(Hello, Athens!)
    end

    View Slide

  143. View Slide

  144. View Slide

  145. Are all those options
    worth our while?

    View Slide

  146. View Slide

  147. Let’s fix some stuff!

    View Slide

  148. and & or have the
    same precedence

    View Slide

  149. So many nils floating
    around

    View Slide

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

    View Slide

  151. Mutable strings

    View Slide

  152. Even JavaScript got
    this right…

    View Slide

  153. Reassignable
    constants

    View Slide

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

  155. Class variables

    View Slide

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

  157. Poorly named
    methods

    View Slide

  158. Kernel#puts

    View Slide

  159. Kernel#println,
    anyone?

    View Slide

  160. Kernel#print

    View Slide

  161. defined?

    View Slide

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

    View Slide

  163. Enumerable#include?

    View Slide

  164. Enumerable#includes?

    View Slide

  165. Kernel#%

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  171. Perl-style global
    variables

    View Slide

  172. $:

    View Slide

  173. $LOAD_PATH

    View Slide

  174. $;

    View Slide

  175. $FIELD_SEPARATOR

    View Slide

  176. $*

    View Slide

  177. $ARGV

    View Slide

  178. JRuby defines the
    English aliases by
    default

    View Slide

  179. Ruby 4.0 will do this
    as well!

    View Slide

  180. WTF? Global
    variables?

    View Slide

  181. Even Java doesn’t
    have globals…

    View Slide

  182. The future of the
    standard library

    View Slide

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

    View Slide

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

    View Slide

  185. Horrible APIs

    View Slide

  186. net/http anyone?

    View Slide

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

    View Slide

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

    View Slide

  189. View Slide

  190. View Slide

  191. View Slide

  192. View Slide

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

    View Slide

  194. 2. Remove everything
    outdated/obscure

    View Slide

  195. 3. Leverage modern
    Ruby feature in the
    Standard Library

    View Slide

  196. Epilogue

    View Slide

  197. When will Ruby 4 be
    released?

    View Slide

  198. Ruby 4.0 will likely
    never happen

    View Slide

  199. View Slide

  200. Ruby 4.0 is already
    here!

    View Slide

  201. Crystal

    View Slide

  202. Clojure

    View Slide

  203. Elixir

    View Slide

  204. Scala

    View Slide

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

    View Slide

  206. Felina

    View Slide

  207. One more thing…

    View Slide

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

    View Slide

  209. File tickets

    View Slide

  210. Send patches

    View Slide

  211. Blog about the issues

    View Slide

  212. Speak about the
    issues

    View Slide

  213. Let’s make Ruby
    better together!

    View Slide

  214. Ruby
    Ruby

    View Slide

  215. Epilogue
    twitter: @bbatsov
    github: @bbatsov
    http//batsov.com
    http://emacsredux.com
    Athens Ruby Meetup
    Athens,
    Greece
    18.11.2016

    View Slide