Ruby 4.0: To Infinity and Beyond (RubyConf.by 2017)

Ruby 4.0: To Infinity and Beyond (RubyConf.by 2017)

Slide deck from my RubyConf.by 2017 presentation

1be785d1d788b82929e55fc83a9f0aaa?s=128

Bozhidar Batsov

April 02, 2017
Tweet

Transcript

  1. None
  2. Прывітанне!

  3. Божидар

  4. Bozhidar

  5. Bozho cool

  6. Bozo not cool

  7. Bug cool

  8. None
  9. None
  10. bbatsov

  11. Ruby & Rails style guides

  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. join@toptal.com

  22. None
  23. Our Mission

  24. Find the best remote freelance jobs

  25. For the best freelancers

  26. And have them work on their own terms…

  27. None
  28. None
  29. None
  30. None
  31. None
  32. https://www.toptal.com/talent/apply

  33. None
  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. None
  42. None
  43. None
  44. Ruby 4.0: To INFINITY and Beyound by Bozhidar Batsov

  45. None
  46. Not on Ruby’s Core Team

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

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

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

    they want.
  50. None
  51. The track record of recent Ruby innovation

  52. Ruby != MRI

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

  54. Ruby 2.0

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

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

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

    no longer experimental feature
  58. Ruby 2.2

  59. Nada

  60. Ruby 2.3

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

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

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

    case mappings
  64. Ruby 2.5?

  65. Java innovates more!

  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. 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.
  70. 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.
  71. 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.
  72. None
  73. What about Ruby 3.0?

  74. Little is known about it…

  75. Optional static typing? rejected

  76. Duck inference?

  77. Better support for concurrent & parallel programming

  78. None
  79. 3 times faster performance?

  80. Getting rid of some quirky features?

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

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

  83. None
  84. Ruby 4.0

  85. Codename Buzz

  86. Ruby 4x4

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

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

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

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

  91. Ruby 4.0, the language

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

  93. Design principle #1

  94. Continue to optimize for happiness

  95. Add some useful new features

  96. Immutable data structures

  97. vector

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

  99. immutable hash

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

  101. immutable set

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

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

  104. Static typing and runtime contracts

  105. Inspired by RDL

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

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

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

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

  110. Inspired by concurrent-ruby

  111. CSP

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

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

  115. Simplicity

  116. Simplicity is the ultimate sophistication.

  117. Less is more

  118. Simplicity leads to happiness.

  119. Let’s drop some stuff

  120. Let’s drop some useless stuff

  121. for loops

  122. for name in names puts name end

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

  124. BEGIN & END

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

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

  127. Kernel#at_exit, anyone?

  128. flip-flops

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

    end
  130. block comments

  131. =begin comment line another comment line =end

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

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

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

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

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

  137. $SAFE

  138. Let’s drop some redundant stuff

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

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

  141. core library method aliases

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

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

  144. map reduce find filter format length raise

  145. procs

  146. No arity check

  147. Non-local return

  148. Do we really need them?

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

    lambdas…
  150. None
  151. Single-quoted string literals

  152. None
  153. A ton of obscure %- something literals

  154. %s, %x, %w, %W, %r, %q, %Q, %, %i

  155. So excited to be here!

  156. puts "Hello, Minsk!" puts "Hello, Minsk!" puts "Hello, Minsk!"

  157. for i in 1..3 puts "Hello, Minsk!" end

  158. 3.times do puts "Hello, Minsk!" end

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

  160. 3.times do puts %Q(Hello, Minsk!) end

  161. 3.times do puts 'Hello, Minsk!' end

  162. 3.times do puts %q(Hello, Minsk!) end

  163. None
  164. None
  165. Are all those options worth our while?

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

  168. and & or have the same precedence

  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. Epilogue 1/2

  224. When will Ruby 4 be released?

  225. Ruby 4.0 will likely never happen

  226. None
  227. Ruby 4.0 is already here!

  228. Crystal

  229. Clojure

  230. Elixir

  231. Scala

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

    evenly distributed.”
  233. Felina

  234. One more thing…

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

  236. –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..”
  237. File tickets

  238. Send patches

  239. Blog about the issues

  240. Speak about the issues

  241. Let’s make Ruby better together!

  242. Ruby Ruby

  243. Epilogue twitter: @bbatsov github: @bbatsov http//batsov.com http://emacsredux.com RubyConf.by Minsk, Belarus

    02.04.2017