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

Ruby 4.0: To Infinity and Beyond (RailsIsrael 2016)

Ruby 4.0: To Infinity and Beyond (RailsIsrael 2016)

Slide deck from my Ruby 4.0 presentation at RailsIsrael 2016.

Efd2550fb5f3059d815e731ecd61b701?s=128

Bozhidar Batsov

November 14, 2016
Tweet

Transcript

  1. None
  2. םוֹלָׁש

  3. Божидар

  4. None
  5. Bozhidar

  6. Bozho cool

  7. Bozo not cool

  8. Bug cool

  9. None
  10. None
  11. bbatsov

  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. Ruby 4.0: To INFINITY and Beyound by Bozhidar Batsov

  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. Build the things your users need, instead of the things

    they want.
  27. None
  28. The track record of recent Ruby innovation

  29. Ruby != MRI

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

  31. Ruby 2.0

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

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

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

    no longer experimental feature
  35. Ruby 2.2

  36. Nada

  37. Ruby 2.3

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

  39. Ruby 2.4

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

    case mappings
  41. Java innovates more!

  42. What about Ruby 3.0?

  43. Little is known about it…

  44. Optional static typing? rejected

  45. Duck inference?

  46. Better support for concurrent & parallel programming

  47. None
  48. 3 times faster performance?

  49. Getting rid of some quirky features?

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

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

  52. Ruby 4.0

  53. Codename Buzz

  54. Ruby 4x4

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

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

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

  58. Ruby 4.0, the language

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

  60. Design principle #1

  61. Continue to optimize for happiness

  62. Add some useful new features

  63. Immutable data structures

  64. vector

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

  66. immutable hash

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

  68. immutable set

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

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

  71. Static typing and runtime contracts

  72. Inspired by RDL

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

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

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

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

  77. Inspired by concurrent-ruby

  78. CSP

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

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

  82. Simplicity

  83. Simplicity is the ultimate sophistication.

  84. Less is more

  85. Simplicity leads to happiness.

  86. Let’s drop some stuff

  87. Let’s drop some useless stuff

  88. for loops

  89. for name in names puts name end

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

  91. BEGIN & END

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

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

  94. Kernel#at_exit, anyone?

  95. flip-flops

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

    end
  97. block comments

  98. =begin comment line another comment line =end

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

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

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

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

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

  104. Let’s drop some redundant stuff

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

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

  107. core library method aliases

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

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

  110. map reduce find filter format length raise

  111. procs

  112. No arity check

  113. Non-local return

  114. Do we really need them?

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

    lambdas…
  116. None
  117. Single-quoted string literals

  118. None
  119. A ton of obscure %- something literals

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

  121. So excited to be here!

  122. puts "Hello, Tel Aviv!" puts "Hello, Tel Aviv!" puts "Hello,

    Tel Aviv!"
  123. for i in 1..3 puts "Hello, Tel Aviv!" end

  124. 3.times do puts "Hello, Tel Aviv!" end

  125. 3.times do puts %(Hello, Tel Aviv!) end

  126. 3.times do puts %Q(Hello, Tel Aviv!) end

  127. 3.times do puts 'Hello, Tel Aviv!' end

  128. 3.times do puts %q(Hello, Tel Aviv!) end

  129. None
  130. None
  131. Are all those options worth our while?

  132. None
  133. Let’s fix some stuff!

  134. and & or have the same precedence

  135. So many nils floating around

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

  137. Mutable strings

  138. Even JavaScript got this right…

  139. Reassignable constants

  140. 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
  141. Class variables

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

  144. Kernel#puts

  145. Kernel#println, anyone?

  146. Kernel#print

  147. defined?

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

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

  150. Enumerable#includes?

  151. Kernel#%

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

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

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

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

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

  157. Perl-style global variables

  158. $:

  159. $LOAD_PATH

  160. $;

  161. $FIELD_SEPARATOR

  162. $*

  163. $ARGV

  164. JRuby defines the English aliases by default

  165. Ruby 4.0 will do this as well!

  166. WTF? Global variables?

  167. Even Java doesn’t have globals…

  168. The future of the standard library

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

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

  171. Horrible APIs

  172. net/http anyone?

  173. 1. Move the important bits to the Core Library

  174. 2. Remove everything outdated/obscure

  175. 3. Leverage modern Ruby feature in the Standard Library

  176. Epilogue

  177. When will Ruby 4 be released?

  178. Ruby 4.0 will likely never happen

  179. None
  180. Ruby 4.0 is already here!

  181. Crystal

  182. Clojure

  183. Elixir

  184. Scala

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

    evenly distributed.”
  186. Felina

  187. Epilogue twitter: @bbatsov github: @bbatsov http//batsov.com http://emacsredux.com RailsIsrael 2016 Tel

    Aviv, Israel 14.11.2016