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

Ruby 4.0: To Infinity and Beyond (Athens Ruby Meetup)

Ruby 4.0: To Infinity and Beyond (Athens Ruby Meetup)

The slide deck from the presentation I gave at the Athens Ruby Meetup on 18.11.2016.

Efd2550fb5f3059d815e731ecd61b701?s=128

Bozhidar Batsov

November 22, 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. Ruby & Rails style guides

  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. Ruby 4.0: To INFINITY and Beyound by Bozhidar Batsov

  28. None
  29. Not on Ruby’s Core Team

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

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

  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 (&.)

  45. Ruby 2.4

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

    case mappings
  47. Java innovates more!

  48. 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.
  49. 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.
  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. None
  55. What about Ruby 3.0?

  56. Little is known about it…

  57. Optional static typing? rejected

  58. Duck inference?

  59. Better support for concurrent & parallel programming

  60. None
  61. 3 times faster performance?

  62. Getting rid of some quirky features?

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

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

  65. None
  66. Ruby 4.0

  67. Codename Buzz

  68. Ruby 4x4

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

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

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

  72. Ruby 4.0, the language

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

  74. Design principle #1

  75. Continue to optimize for happiness

  76. Add some useful new features

  77. Immutable data structures

  78. vector

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

  80. immutable hash

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

  82. immutable set

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

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

  85. Static typing and runtime contracts

  86. Inspired by RDL

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

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

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

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

  91. Inspired by concurrent-ruby

  92. CSP

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

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

  96. Simplicity

  97. Simplicity is the ultimate sophistication.

  98. Less is more

  99. Simplicity leads to happiness.

  100. Let’s drop some stuff

  101. Let’s drop some useless stuff

  102. for loops

  103. for name in names puts name end

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

  105. BEGIN & END

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

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

  108. Kernel#at_exit, anyone?

  109. flip-flops

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

    end
  111. block comments

  112. =begin comment line another comment line =end

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

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

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

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

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

  118. Let’s drop some redundant stuff

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

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

  121. core library method aliases

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

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

  124. map reduce find filter format length raise

  125. procs

  126. No arity check

  127. Non-local return

  128. Do we really need them?

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

    lambdas…
  130. None
  131. Single-quoted string literals

  132. None
  133. A ton of obscure %- something literals

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

  135. So excited to be here!

  136. puts "Hello, Athens!" puts "Hello, Athens!" puts "Hello, Athens!"

  137. for i in 1..3 puts "Hello, Athens!" end

  138. 3.times do puts "Hello, Athens!" end

  139. 3.times do puts %(Hello, Athens!) end

  140. 3.times do puts %Q(Hello, Athens!) end

  141. 3.times do puts 'Hello, Athens!' end

  142. 3.times do puts %q(Hello, Athens!) end

  143. None
  144. None
  145. Are all those options worth our while?

  146. None
  147. Let’s fix some stuff!

  148. and & or have the same precedence

  149. So many nils floating around

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

  151. Mutable strings

  152. Even JavaScript got this right…

  153. Reassignable constants

  154. 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
  155. Class variables

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

  158. Kernel#puts

  159. Kernel#println, anyone?

  160. Kernel#print

  161. defined?

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

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

  164. Enumerable#includes?

  165. Kernel#%

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

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

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

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

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

  171. Perl-style global variables

  172. $:

  173. $LOAD_PATH

  174. $;

  175. $FIELD_SEPARATOR

  176. $*

  177. $ARGV

  178. JRuby defines the English aliases by default

  179. Ruby 4.0 will do this as well!

  180. WTF? Global variables?

  181. Even Java doesn’t have globals…

  182. The future of the standard library

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

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

  185. Horrible APIs

  186. net/http anyone?

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

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

    the most? Why so?
  189. None
  190. None
  191. None
  192. None
  193. 1. Move the important bits to the Core Library

  194. 2. Remove everything outdated/obscure

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

  196. Epilogue

  197. When will Ruby 4 be released?

  198. Ruby 4.0 will likely never happen

  199. None
  200. Ruby 4.0 is already here!

  201. Crystal

  202. Clojure

  203. Elixir

  204. Scala

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

    evenly distributed.”
  206. Felina

  207. One more thing…

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

  209. File tickets

  210. Send patches

  211. Blog about the issues

  212. Speak about the issues

  213. Let’s make Ruby better together!

  214. Ruby Ruby

  215. Epilogue twitter: @bbatsov github: @bbatsov http//batsov.com http://emacsredux.com Athens Ruby Meetup

    Athens, Greece 18.11.2016