Ruby 4: To Infinity and Beyond

1be785d1d788b82929e55fc83a9f0aaa?s=47 Bozhidar Batsov
September 30, 2017

Ruby 4: To Infinity and Beyond

Slide deck from my presentation at EuRuKo 2017 in Budapest.

1be785d1d788b82929e55fc83a9f0aaa?s=128

Bozhidar Batsov

September 30, 2017
Tweet

Transcript

  1. None
  2. Hello!

  3. Божидар

  4. Bozhidar

  5. Божo

  6. Bozho cool

  7. Bozo not cool

  8. Bug cool

  9. Sofia, Bulgaria Sofia, Bulgaria

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

  11. None
  12. None
  13. bbatsov

  14. Ruby & Rails style guides

  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. Not on Ruby’s Core Team

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

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

  26. We’re aware of all of our mistakes

  27. Compatibility is important

  28. Ruby has survived for 24 years

  29. None
  30. People are still making a living a with Ruby

  31. People are still making a living with COBOL

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

    they want.
  33. None
  34. The track record of recent Ruby innovation

  35. Ruby != MRI

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

  37. Ruby 2.0

  38. •keyword arguments •%i •UTF-8 is now the default source file

    encoding •Refinements (experimental feature)
  39. Ruby 2.1

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

    feature
  41. Ruby 2.2

  42. Nada

  43. Ruby 2.3

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

    (<<~)
  45. Ruby 2.4

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

  47. Ruby 2.5?

  48. •Top-level constant look-up is removed •rescue/else/ensure are allowed inside do/end

    blocks •refinements take place in string interpolations

  49. Java innovates more!

  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.
  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.
  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.
  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.
  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.
  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.
  56. None
  57. Trailblazer

  58. Hanami

  59. What about Ruby 3.0?

  60. Little is known about it…

  61. Little concrete is known about it…

  62. Optional static typing? rejected

  63. Duck inference?

  64. Better support for concurrent & parallel programming

  65. None
  66. 3 times faster performance?

  67. mjit?

  68. Getting rid of some quirky features?

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

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

  71. Who said Ruby is dead? — Matz

  72. Ruby is dead!

  73. None
  74. None
  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…”
  76. Stewardship: The Sobering Parts https://www.youtube.com/watch?v=2y5Pv4yN0b0

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

  79. None
  80. Codename Buzz

  81. Ruby 4x4

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

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

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

  85. Ruby 4.0, the language

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

  87. Design principle #1

  88. Continue to optimize for happiness

  89. Add some useful new features

  90. Immutable data structures

  91. vector

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

  93. immutable hash

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

  95. immutable set

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

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

  98. Static typing and runtime contracts

  99. Inspired by RDL

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

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

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

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

  104. Inspired by concurrent-ruby

  105. CSP

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

    messages.take puts msg
  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(' ')
  108. Namespaces!

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

  110. module A::B::M end

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

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

    end end
  113. Pattern Matching

  114. Deprecation API

  115. class SomeClass extend Gem::Deprecate def no_more close end deprecate :no_more,

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

    end def close # new logic here end end
  117. class SomeClass deprecate scope: :class, version: 2.1 def ala #

    something truly deep end def bala # something extremely profound end end
  118. Design principle #2

  119. Simplicity

  120. Simplicity is the ultimate sophistication.

  121. Less is more

  122. Simplicity leads to happiness.

  123. Let’s drop some stuff

  124. Let’s drop some useless stuff

  125. for loops

  126. for name in names puts name end

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

  128. autoload

  129. BEGIN & END

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

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

  132. Kernel#at_exit, anyone?

  133. flip-flops

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

    end
  135. block comments

  136. =begin comment line another comment line =end

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

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

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

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

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

  142. $SAFE

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

  144. None
  145. Refinements

  146. Let’s drop some redundant stuff

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

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

  149. core library method aliases

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

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

  152. map reduce find filter format length raise

  153. Farewell, fail!

  154. procs

  155. No arity check

  156. Non-local return

  157. Do we really need them?

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

    lambdas…
  159. None
  160. Single-quoted string literals

  161. None
  162. A ton of obscure %-something literals

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

  164. %r, %q, %Q

  165. So excited to be here!

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

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

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

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

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

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

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

  173. None
  174. None
  175. Are all those options worth our while?

  176. None
  177. Let’s fix some stuff!

  178. and & or have the same precedence

  179. So many nils floating around

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

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

    => nil pry(main)> 1.nonzero? => 1
  182. Mutable strings

  183. Even JavaScript got this right…

  184. Reassignable constants

  185. Reassignable constants

  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
  187. None
  188. Class variables

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

  191. Kernel#puts

  192. Kernel#println, anyone?

  193. Kernel#print

  194. defined?

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

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

  198. Enumerable#includes?

  199. Kernel#%

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

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

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

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

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

  205. Perl-style global variables

  206. $:

  207. $LOAD_PATH

  208. $;

  209. $FIELD_SEPARATOR

  210. $*

  211. $ARGV

  212. JRuby defines the English aliases by default

  213. Ruby 4.0 will do this as well!

  214. WTF? Global variables?

  215. None
  216. Even Java doesn’t have globals…

  217. The future of the standard library

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

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

  220. Horrible APIs

  221. net/http anyone?

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

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

    the most? Why so?
  224. None
  225. None
  226. None
  227. None
  228. 1. Move the important bits to the Core Library

  229. 2. Remove everything outdated/obscure

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

  231. Wait, there’s more!

  232. Formal language specification and compatibility test suite

  233. Roadmaps for future Ruby releases

  234. Epilogue

  235. When will Ruby 4 be released?

  236. Ruby 4.0 will likely never happen

  237. None
  238. Ruby 4.0 ETA ~ 2048

  239. Ruby 4.0 is already here!

  240. None
  241. Opal

  242. None
  243. None
  244. Clojure

  245. Elixir

  246. Scala

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

    evenly distributed.”
  248. Felina

  249. One more thing…

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

    community’s project.”
  251. File tickets

  252. Send patches

  253. Blog about the issues

  254. Speak about the issues

  255. Let’s make Ruby better together!

  256. Ruby Ruby

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

    Hungary 30.09.2017