Save 37% off PRO during our Black Friday Sale! »

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.

Efd2550fb5f3059d815e731ecd61b701?s=128

Bozhidar Batsov

June 11, 2017
Tweet

Transcript

  1. None
  2. Hello!

  3. Божидар

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

  7. None
  8. Not on Ruby’s Core Team

  9. –Matz “We’ll aim to release Ruby 3 for the Olympic

    Games in Tokyo in 2020.”
  10. Ruby is now mature

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

    they want.
  12. None
  13. The track record of recent Ruby innovation

  14. Ruby != MRI

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

  16. Ruby 2.0

  17. • keyword arguments • %i • UTF-8 is now the

    default source file encoding • Refinements (experimental feature)
  18. Ruby 2.1

  19. • Rational/Complex Literal • defs return value • Refinements are

    no longer experimental feature
  20. Ruby 2.2

  21. Nada

  22. Ruby 2.3

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

    • squiggly heredocs (<<~)
  24. Ruby 2.4

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

    case mappings
  26. Ruby 2.5?

  27. Java innovates more!

  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.
  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.
  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.
  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.
  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.
  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.
  34. None
  35. What about Ruby 3.0?

  36. Little is known about it…

  37. Optional static typing? rejected

  38. Duck inference?

  39. Better support for concurrent & parallel programming

  40. None
  41. 3 times faster performance?

  42. Getting rid of some quirky features?

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

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

  45. None
  46. Ruby 4.0

  47. Codename Buzz

  48. Ruby 4x4

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

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

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

  52. Ruby 4.0, the language

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

  54. Design principle #1

  55. Continue to optimize for happiness

  56. Add some useful new features

  57. Immutable data structures

  58. vector

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

  60. immutable hash

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

  62. immutable set

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

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

  65. Static typing and runtime contracts

  66. Inspired by RDL

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

  68. pre { |x| x > 0 } post { |r,x|

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

    y>=0 }}' def sqrt(x) # return the square root of x end
  70. Better concurrency APIs

  71. Inspired by concurrent-ruby

  72. CSP

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

    messages.take puts msg
  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(' ')
  75. Design principle #2

  76. Simplicity

  77. Simplicity is the ultimate sophistication.

  78. Less is more

  79. Simplicity leads to happiness.

  80. Let’s drop some stuff

  81. Let’s drop some useless stuff

  82. for loops

  83. for name in names puts name end

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

  85. BEGIN & END

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

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

  88. Kernel#at_exit, anyone?

  89. flip-flops

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

    end
  91. block comments

  92. =begin comment line another comment line =end

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

  94. class SomeClass =begin This is a top comment. Or is

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

    it? =end def some_method end end
  96. Character literals

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

  98. $SAFE

  99. Let’s drop some redundant stuff

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

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

  102. core library method aliases

  103. collect => map inject => reduce detect => find select

    => find_all sprintf => format length => size raise => fail
  104. Where is filter?

  105. map reduce find filter format length raise

  106. procs

  107. No arity check

  108. Non-local return

  109. Do we really need them?

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

    lambdas…
  111. None
  112. Single-quoted string literals

  113. None
  114. A ton of obscure %- something literals

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

  116. %r, %q, %Q

  117. So excited to be here!

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

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

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

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

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

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

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

  125. None
  126. None
  127. Are all those options worth our while?

  128. None
  129. Let’s fix some stuff!

  130. and & or have the same precedence

  131. So many nils floating around

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

  133. Mutable strings

  134. Even JavaScript got this right…

  135. Reassignable constants

  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
  137. None
  138. Class variables

  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"
  140. Poorly named methods

  141. Kernel#puts

  142. Kernel#println, anyone?

  143. Kernel#print

  144. defined?

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

    => nil [3] pry(main)> defined? TrueClass => "constant"
  146. None
  147. Enumerable#include?

  148. Enumerable#includes?

  149. Kernel#%

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

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

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

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

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

  155. Perl-style global variables

  156. $:

  157. $LOAD_PATH

  158. $;

  159. $FIELD_SEPARATOR

  160. $*

  161. $ARGV

  162. JRuby defines the English aliases by default

  163. Ruby 4.0 will do this as well!

  164. WTF? Global variables?

  165. None
  166. Even Java doesn’t have globals…

  167. The future of the standard library

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

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

  170. Horrible APIs

  171. net/http anyone?

  172. The Kill List • Net::* • DRb • REXML •

    RSS • Rinda • WEBrick • XML
  173. What are the parts of the standard library you dislike

    the most? Why so?
  174. None
  175. None
  176. None
  177. None
  178. 1. Move the important bits to the Core Library

  179. 2. Remove everything outdated/obscure

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

  181. Wait, there’s more!

  182. Formal language specification and compatibility test suite

  183. Roadmaps for future Ruby releases

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

    with MRI
  185. Epilogue

  186. When will Ruby 4 be released?

  187. Ruby 4.0 will likely never happen

  188. None
  189. Ruby 4.0 is already here!

  190. Crystal

  191. Clojure

  192. Elixir

  193. Scala

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

    evenly distributed.”
  195. Felina

  196. One more thing…

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

  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..”
  199. File tickets

  200. Send patches

  201. Blog about the issues

  202. Speak about the issues

  203. Let’s make Ruby better together!

  204. Ruby Ruby

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

    Kenya 09.06.2017