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

Ruby 4.0: To Infinity and Beyond

Ruby 4.0: To Infinity and Beyond

Slide-deck from my RubyC 2017 presentation.

Efd2550fb5f3059d815e731ecd61b701?s=128

Bozhidar Batsov

June 04, 2017
Tweet

Transcript

  1. None
  2. Вiтаю!

  3. Божидар

  4. Bozhidar

  5. Bozho cool

  6. Bozo not cool

  7. Божo

  8. Bug cool

  9. Magical Sofia City

  10. None
  11. bbatsov

  12. Ruby & Rails style guides

  13. None
  14. Emacs fanatic

  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. Toptal

  22. None
  23. join@toptal.com

  24. None
  25. Our Mission

  26. Find the best remote freelance jobs

  27. For the best freelancers

  28. And have them work on their own terms…

  29. None
  30. None
  31. None
  32. None
  33. None
  34. https://www.toptal.com/talent/apply

  35. None
  36. None
  37. None
  38. None
  39. None
  40. Ruby 4.0: To INFINITY and Beyound by Bozhidar Batsov

  41. None
  42. Not on Ruby’s Core Team

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

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

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

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

    they want.
  47. Henry Ford quote

  48. The track record of recent Ruby innovation

  49. Ruby != MRI

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

  51. Ruby 2.0

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

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

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

    no longer experimental feature
  55. Ruby 2.2

  56. Nada

  57. Ruby 2.3

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

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

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

    case mappings
  61. Ruby 2.5?

  62. Java innovates more!

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

  70. None
  71. What about Ruby 3.0?

  72. Little is known about it…

  73. Optional static typing? rejected

  74. Duck inference?

  75. Better support for concurrent & parallel programming

  76. None
  77. 3 times faster performance?

  78. Getting rid of some quirky features?

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

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

  81. None
  82. Ruby 4.0

  83. Codename Buzz

  84. Ruby 4x4

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

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

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

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

  89. JRuby in 2017: Fast, Compatible and Concurrent

  90. Ruby 4.0, the language

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

  92. Design principle #1

  93. Continue to optimize for happiness

  94. Add some useful new features

  95. Immutable data structures

  96. vector

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

  98. immutable hash

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

  100. immutable set

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

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

  103. Static typing and runtime contracts

  104. Inspired by RDL

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

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

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

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

  109. Inspired by concurrent-ruby

  110. CSP

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

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

  114. Simplicity

  115. Simplicity is the ultimate sophistication.

  116. Less is more

  117. Simplicity leads to happiness.

  118. Let’s drop some stuff

  119. Let’s drop some useless stuff

  120. for loops

  121. for name in names puts name end

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

  123. BEGIN & END

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

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

  126. Kernel#at_exit, anyone?

  127. flip-flops

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

    end
  129. block comments

  130. =begin comment line another comment line =end

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

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

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

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

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

  136. Let’s drop some redundant stuff

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

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

  139. core library method aliases

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

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

  142. map reduce find filter format length raise

  143. procs

  144. No arity check

  145. Non-local return

  146. Do we really need them?

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

    lambdas…
  148. None
  149. Single-quoted string literals

  150. None
  151. Some obscure %-something literals

  152. %r, %q, %Q

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

  154. So excited to be here!

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

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

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

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

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

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

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

  162. Damn, that escalated quickly :-)

  163. Decisions are hard…

  164. Are all those options worth our while?

  165. None
  166. Let’s fix some stuff!

  167. and & or have the same precedence

  168. && has higher precedence than ||

  169. So many nils floating around

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

  171. Mutable strings

  172. Even JavaScript got this right…

  173. Reassignable constants

  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
  175. None
  176. Class variables

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

  179. Kernel#puts

  180. Kernel#println, anyone?

  181. Kernel#print

  182. defined?

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

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

  186. Enumerable#includes?

  187. Kernel#%

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

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

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

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

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

  193. Perl-style global variables

  194. $:

  195. $LOAD_PATH

  196. $;

  197. $FIELD_SEPARATOR

  198. $*

  199. $ARGV

  200. JRuby defines the English aliases by default

  201. Ruby 4.0 will do this as well!

  202. WTF? Global variables?

  203. None
  204. Even Java doesn’t have globals…

  205. The future of the standard library

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

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

  208. Horrible APIs

  209. net/http anyone?

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

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

    the most? Why so?
  212. None
  213. None
  214. None
  215. None
  216. 1. Move the important bits to the Core Library

  217. 2. Remove everything outdated/obscure

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

  219. Wait, there’s more!

  220. Formal language specification and compatibility test suite

  221. Roadmaps for future Ruby releases

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

    with MRI
  223. $SAFE

  224. Epilogue 1/2

  225. When will Ruby 4 be released?

  226. Ruby 4.0 will likely never happen

  227. None
  228. Ruby 4.0 is already here!

  229. Crystal

  230. Clojure

  231. Elixir

  232. Scala

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

    evenly distributed.”
  234. Felina

  235. One more thing…

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

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

  239. Send patches

  240. Blog about the issues

  241. Speak about the issues

  242. Let’s make Ruby better together!

  243. Ruby Ruby

  244. None
  245. None
  246. None
  247. Epilogue twitter: @bbatsov github: @bbatsov http//batsov.com http://emacsredux.com RubyC Kyiv, Ukraine

    03.06.2017