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

Ruby 4.0: To Infinity and Beyond

Ruby 4.0: To Infinity and Beyond

Slide-deck from my RubyC 2017 presentation.

Bozhidar Batsov

June 04, 2017
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. View Slide

  2. Вiтаю!

    View Slide

  3. Божидар

    View Slide

  4. Bozhidar

    View Slide

  5. Bozho
    cool

    View Slide

  6. Bozo
    not cool

    View Slide

  7. Божo

    View Slide

  8. Bug
    cool

    View Slide

  9. Magical Sofia City

    View Slide

  10. View Slide

  11. bbatsov

    View Slide

  12. Ruby & Rails
    style guides

    View Slide

  13. View Slide

  14. Emacs fanatic

    View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. Toptal

    View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. Our Mission

    View Slide

  26. Find the best remote
    freelance jobs

    View Slide

  27. For the best freelancers

    View Slide

  28. And have them work on their
    own terms…

    View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. View Slide

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

    View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. View Slide

  39. View Slide

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

    View Slide

  41. View Slide

  42. Not on Ruby’s Core Team

    View Slide

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

    View Slide

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

    View Slide

  45. Ruby is now mature

    View Slide

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

    View Slide

  47. Henry Ford quote

    View Slide

  48. The track record
    of
    recent Ruby innovation

    View Slide

  49. Ruby != MRI

    View Slide

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

    View Slide

  51. Ruby 2.0

    View Slide

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

    View Slide

  53. Ruby 2.1

    View Slide

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

    View Slide

  55. Ruby 2.2

    View Slide

  56. Nada

    View Slide

  57. Ruby 2.3

    View Slide

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

    View Slide

  59. Ruby 2.4

    View Slide

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

    View Slide

  61. Ruby 2.5?

    View Slide

  62. Java innovates more!

    View Slide

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

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

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

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

    View Slide

  70. View Slide

  71. What about Ruby 3.0?

    View Slide

  72. Little is known about it…

    View Slide

  73. Optional static typing?
    rejected

    View Slide

  74. Duck inference?

    View Slide

  75. Better support for concurrent
    & parallel programming

    View Slide

  76. View Slide

  77. 3 times faster performance?

    View Slide

  78. Getting rid of some quirky
    features?

    View Slide

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

    View Slide

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

    View Slide

  81. View Slide

  82. Ruby 4.0

    View Slide

  83. Codename Buzz

    View Slide

  84. Ruby 4x4

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  89. JRuby in 2017: Fast,
    Compatible and Concurrent

    View Slide

  90. Ruby 4.0,
    the language

    View Slide

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

    View Slide

  92. Design principle #1

    View Slide

  93. Continue to optimize for
    happiness

    View Slide

  94. Add some useful new features

    View Slide

  95. Immutable data structures

    View Slide

  96. vector

    View Slide

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

    View Slide

  98. immutable hash

    View Slide

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

    View Slide

  100. immutable set

    View Slide

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

    View Slide

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

    View Slide

  103. Static typing and runtime
    contracts

    View Slide

  104. Inspired by RDL

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  108. Better concurrency APIs

    View Slide

  109. Inspired by concurrent-ruby

    View Slide

  110. CSP

    View Slide

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

    View Slide

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

  113. Design principle #2

    View Slide

  114. Simplicity

    View Slide

  115. Simplicity is the ultimate
    sophistication.

    View Slide

  116. Less is more

    View Slide

  117. Simplicity leads
    to happiness.

    View Slide

  118. Let’s drop some stuff

    View Slide

  119. Let’s drop some
    useless
    stuff

    View Slide

  120. for loops

    View Slide

  121. for name in names
    puts name
    end

    View Slide

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

    View Slide

  123. BEGIN & END

    View Slide

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

    View Slide

  125. puts 'Bye!'
    puts 'Starting...'
    puts 'Processing...'

    View Slide

  126. Kernel#at_exit, anyone?

    View Slide

  127. flip-flops

    View Slide

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

    View Slide

  129. block comments

    View Slide

  130. =begin
    comment line
    another comment line
    =end

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  134. Character literals

    View Slide

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

    View Slide

  136. Let’s drop some
    redundant
    stuff

    View Slide

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

    View Slide

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

    View Slide

  139. core library method aliases

    View Slide

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

    View Slide

  141. Where is filter?

    View Slide

  142. map
    reduce
    find
    filter
    format
    length
    raise

    View Slide

  143. procs

    View Slide

  144. No arity check

    View Slide

  145. Non-local return

    View Slide

  146. Do we really need them?

    View Slide

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

    View Slide

  148. View Slide

  149. Single-quoted string literals

    View Slide

  150. View Slide

  151. Some obscure %-something
    literals

    View Slide

  152. %r, %q, %Q

    View Slide

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

    View Slide

  154. So excited to be here!

    View Slide

  155. puts "Hello, Kyiv!"
    puts "Hello, Kyiv!"
    puts "Hello, Kyiv!"

    View Slide

  156. for i in 1..3
    puts "Hello, Kyiv!"
    end

    View Slide

  157. 3.times do
    puts "Hello, Kyiv!"
    end

    View Slide

  158. 3.times do
    puts %(Hello, Kyiv!)
    end

    View Slide

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

    View Slide

  160. 3.times do
    puts 'Hello, Kyiv!'
    end

    View Slide

  161. 3.times do
    puts %q(Hello, Kyiv!)
    end

    View Slide

  162. Damn, that escalated
    quickly :-)

    View Slide

  163. Decisions are hard…

    View Slide

  164. Are all those options worth
    our while?

    View Slide

  165. View Slide

  166. Let’s fix some stuff!

    View Slide

  167. and & or have the same
    precedence

    View Slide

  168. &&
    has higher precedence than
    ||

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

    View Slide

  224. Epilogue
    1/2

    View Slide

  225. When will Ruby 4 be
    released?

    View Slide

  226. Ruby 4.0 will likely never
    happen

    View Slide

  227. View Slide

  228. Ruby 4.0 is already here!

    View Slide

  229. Crystal

    View Slide

  230. Clojure

    View Slide

  231. Elixir

    View Slide

  232. Scala

    View Slide

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

    View Slide

  234. Felina

    View Slide

  235. One more thing…

    View Slide

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

    View Slide

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

  238. File tickets

    View Slide

  239. Send patches

    View Slide

  240. Blog about the issues

    View Slide

  241. Speak about the issues

    View Slide

  242. Let’s make Ruby better
    together!

    View Slide

  243. Ruby
    Ruby

    View Slide

  244. View Slide

  245. View Slide

  246. View Slide

  247. Epilogue
    twitter: @bbatsov
    github: @bbatsov
    http//batsov.com
    http://emacsredux.com
    RubyC
    Kyiv,
    Ukraine
    03.06.2017

    View Slide