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

Ruby 4: To Infinity and Beyond

Bozhidar Batsov
September 30, 2017

Ruby 4: To Infinity and Beyond

Slide deck from my presentation at EuRuKo 2017 in Budapest.

Bozhidar Batsov

September 30, 2017
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. View Slide

  2. Hello!

    View Slide

  3. Божидар

    View Slide

  4. Bozhidar

    View Slide

  5. Божo

    View Slide

  6. Bozho
    cool

    View Slide

  7. Bozo
    not
    cool

    View Slide

  8. Bug
    cool

    View Slide

  9. Sofia, Bulgaria
    Sofia, Bulgaria

    View Slide

  10. Balkan Ruby
    @balkanruby
    https://balkanruby.com
    May 2017 Sofia, Bulgaria

    View Slide

  11. View Slide

  12. View Slide

  13. bbatsov

    View Slide

  14. Ruby & Rails
    style guides

    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. Not on Ruby’s Core Team

    View Slide

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

    View Slide

  25. Ruby is now mature

    View Slide

  26. We’re aware of all of our
    mistakes

    View Slide

  27. Compatibility is important

    View Slide

  28. Ruby has survived for 24
    years

    View Slide

  29. View Slide

  30. People are still making a
    living a with Ruby

    View Slide

  31. People are still making a
    living with COBOL

    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 (&.)
    •squiggly heredocs (<<~)

    View Slide

  45. Ruby 2.4

    View Slide

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

    View Slide

  47. Ruby 2.5?

    View Slide

  48. •Top-level constant look-up is removed
    •rescue/else/ensure are allowed inside do/end blocks
    •refinements take place in string interpolations


    View Slide

  49. Java innovates more!

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

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

  56. View Slide

  57. Trailblazer

    View Slide

  58. Hanami

    View Slide

  59. What about Ruby 3.0?

    View Slide

  60. Little is known about it…

    View Slide

  61. Little concrete
    is known about it…

    View Slide

  62. Optional static typing?
    rejected

    View Slide

  63. Duck inference?

    View Slide

  64. Better support for concurrent
    & parallel programming

    View Slide

  65. View Slide

  66. 3 times faster performance?

    View Slide

  67. mjit?

    View Slide

  68. Getting rid of some quirky
    features?

    View Slide

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

    View Slide

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

    View Slide

  71. Who said Ruby is dead?
    — Matz

    View Slide

  72. Ruby is dead!

    View Slide

  73. View Slide

  74. View Slide

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

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

    View Slide

  77. View Slide

  78. Ruby 4.0:
    To INFINITY
    and Beyond
    by Bozhidar Batsov

    View Slide

  79. View Slide

  80. Codename Buzz

    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. Ruby 4.0,
    the language

    View Slide

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

    View Slide

  87. Design principle #1

    View Slide

  88. Continue to optimize for
    happiness

    View Slide

  89. Add some useful new features

    View Slide

  90. Immutable data structures

    View Slide

  91. vector

    View Slide

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

    View Slide

  93. immutable hash

    View Slide

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

    View Slide

  95. immutable set

    View Slide

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

    View Slide

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

    View Slide

  98. Static typing and runtime
    contracts

    View Slide

  99. Inspired by RDL

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  103. Better concurrency APIs

    View Slide

  104. Inspired by concurrent-ruby

    View Slide

  105. CSP

    View Slide

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

    View Slide

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

  108. Namespaces!

    View Slide

  109. class A
    class B < A
    # bla
    end
    end

    View Slide

  110. module A::B::M
    end

    View Slide

  111. A::B.class_eval do
    module M
    end
    end

    View Slide

  112. # does the right thing always
    namespace A::B
    module M
    end
    end

    View Slide

  113. Pattern Matching

    View Slide

  114. Deprecation API

    View Slide

  115. class SomeClass
    extend Gem::Deprecate
    def no_more
    close
    end
    deprecate :no_more, :close, 2015, 5
    def close
    # new logic here
    end
    end

    View Slide

  116. class SomeClass
    deprecate replacement: close, version: 2
    def no_more
    close
    end
    def close
    # new logic here
    end
    end

    View Slide

  117. class SomeClass
    deprecate scope: :class, version: 2.1
    def ala
    # something truly deep
    end
    def bala
    # something extremely profound
    end
    end

    View Slide

  118. Design principle #2

    View Slide

  119. Simplicity

    View Slide

  120. Simplicity is the ultimate
    sophistication.

    View Slide

  121. Less is more

    View Slide

  122. Simplicity leads
    to happiness.

    View Slide

  123. Let’s drop some stuff

    View Slide

  124. Let’s drop some
    useless
    stuff

    View Slide

  125. for loops

    View Slide

  126. for name in names
    puts name
    end

    View Slide

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

    View Slide

  128. autoload

    View Slide

  129. BEGIN & END

    View Slide

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

    View Slide

  131. puts 'Bye!'
    puts 'Starting...'
    puts 'Processing...'

    View Slide

  132. Kernel#at_exit, anyone?

    View Slide

  133. flip-flops

    View Slide

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

    View Slide

  135. block comments

    View Slide

  136. =begin
    comment line
    another comment line
    =end

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  140. Character literals

    View Slide

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

    View Slide

  142. $SAFE

    View Slide

  143. https://bugs.ruby-lang.org/
    issues/8468

    View Slide

  144. View Slide

  145. Refinements

    View Slide

  146. Let’s drop some
    redundant
    stuff

    View Slide

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

    View Slide

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

    View Slide

  149. core library method aliases

    View Slide

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

    View Slide

  151. Where is filter?

    View Slide

  152. map
    reduce
    find
    filter
    format
    length
    raise

    View Slide

  153. Farewell, fail!

    View Slide

  154. procs

    View Slide

  155. No arity check

    View Slide

  156. Non-local return

    View Slide

  157. Do we really need them?

    View Slide

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

    View Slide

  159. View Slide

  160. Single-quoted string literals

    View Slide

  161. View Slide

  162. A ton of obscure %-something
    literals

    View Slide

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

    View Slide

  164. %r, %q, %Q

    View Slide

  165. So excited to be here!

    View Slide

  166. puts "Hello, Budapest!"
    puts "Hello, Budapest!"
    puts "Hello, Budapest!”

    View Slide

  167. for i in 1..3
    puts "Hello, Budapest!"
    end

    View Slide

  168. 3.times do
    puts "Hello, Budapest!”
    end

    View Slide

  169. 3.times do
    puts %(Hello, Budapest!)
    end

    View Slide

  170. 3.times do
    puts %Q(Hello, Budapest!)
    end

    View Slide

  171. 3.times do
    puts 'Hello, Budapest!’
    end

    View Slide

  172. 3.times do
    puts %q(Hello, Budapest!)
    end

    View Slide

  173. View Slide

  174. View Slide

  175. Are all those options worth
    our while?

    View Slide

  176. View Slide

  177. Let’s fix some stuff!

    View Slide

  178. and & or have the same
    precedence

    View Slide

  179. So many nils floating around

    View Slide

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

    View Slide

  181. pry(main)> 0.zero?
    => true
    pry(main)> 1.zero?
    => false
    pry(main)> 0.nonzero?
    => nil
    pry(main)> 1.nonzero?
    => 1

    View Slide

  182. Mutable strings

    View Slide

  183. Even JavaScript got this
    right…

    View Slide

  184. Reassignable constants

    View Slide

  185. Reassignable constants

    View Slide

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

  187. View Slide

  188. Class variables

    View Slide

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

  190. Poorly named methods

    View Slide

  191. Kernel#puts

    View Slide

  192. Kernel#println, anyone?

    View Slide

  193. Kernel#print

    View Slide

  194. defined?

    View Slide

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

    View Slide

  196. View Slide

  197. Enumerable#include?

    View Slide

  198. Enumerable#includes?

    View Slide

  199. Kernel#%

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  205. Perl-style global variables

    View Slide

  206. $:

    View Slide

  207. $LOAD_PATH

    View Slide

  208. $;

    View Slide

  209. $FIELD_SEPARATOR

    View Slide

  210. $*

    View Slide

  211. $ARGV

    View Slide

  212. JRuby defines the English
    aliases by default

    View Slide

  213. Ruby 4.0 will do this as well!

    View Slide

  214. WTF? Global variables?

    View Slide

  215. View Slide

  216. Even Java doesn’t have
    globals…

    View Slide

  217. The future of the standard
    library

    View Slide

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

    View Slide

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

    View Slide

  220. Horrible APIs

    View Slide

  221. net/http anyone?

    View Slide

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

    View Slide

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

    View Slide

  224. View Slide

  225. View Slide

  226. View Slide

  227. View Slide

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

    View Slide

  229. 2. Remove everything
    outdated/obscure

    View Slide

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

    View Slide

  231. Wait, there’s more!

    View Slide

  232. Formal language specification
    and compatibility test suite

    View Slide

  233. Roadmaps for future Ruby
    releases

    View Slide

  234. Epilogue

    View Slide

  235. When will Ruby 4 be
    released?

    View Slide

  236. Ruby 4.0 will likely never
    happen

    View Slide

  237. View Slide

  238. Ruby 4.0 ETA ~ 2048

    View Slide

  239. Ruby 4.0 is already here!

    View Slide

  240. View Slide

  241. Opal

    View Slide

  242. View Slide

  243. View Slide

  244. Clojure

    View Slide

  245. Elixir

    View Slide

  246. Scala

    View Slide

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

    View Slide

  248. Felina

    View Slide

  249. One more thing…

    View Slide

  250. –Matz
    “Ruby is no longer my project.
    It’s the Ruby community’s
    project.”

    View Slide

  251. File tickets

    View Slide

  252. Send patches

    View Slide

  253. Blog about the issues

    View Slide

  254. Speak about the issues

    View Slide

  255. Let’s make Ruby better
    together!

    View Slide

  256. Ruby
    Ruby

    View Slide

  257. Thanks!
    twitter: @bbatsov
    github: @bbatsov
    http//batsov.com
    http://emacsredux.com
    EuRuKo 2017
    Budapest,
    Hungary
    30.09.2017

    View Slide