Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Polishing Ruby - RubyConf 2014

871fc089cd3cbbc18b9f868c8dd85cce?s=47 Olivier Lacan
November 18, 2014

Polishing Ruby - RubyConf 2014

There are gems out there solving very common problems that could easily be contributed back to Ruby itself. Suggesting a new Ruby feature isn't as daunting as it sounds. As long as you're diligent, you too can push ruby forward.

871fc089cd3cbbc18b9f868c8dd85cce?s=128

Olivier Lacan

November 18, 2014
Tweet

Transcript

  1. Building a better language together Polishing Ruby

  2. Why are you here?

  3. Because you care about Ruby?

  4. Prove it.

  5. Leave it better than you found it.

  6. Nobody’s asking you to change the world.

  7. Just add to it.

  8. Not like this.

  9. Improving the world a little for a good reason is

    better than changing it a lot for a bad one.
  10. +1

  11. @olivierlacan (oh-lee-vee-yay!)

  12. Not a satanist Really.

  13. Please don’t smite me during this talk. @hone02

  14. None
  15. None
  16. APIs. I made one. (wee!)

  17. Ruby with

  18. Rails and

  19. tests I even wrote and stuff.

  20. ★ (pause for wild cheering) ★

  21. What if someone (me) changes the API later?

  22. it breaks the iOS app? What if

  23. What if I forgot my pants and everybody is laughing

    at me right now?
  24. and then go get ice cream! Let’s write some integration

    tests
  25. Given a user,
 When I ask the User API,
 Then

    I should receive data about this user.
  26. user = create(:user, name: “Olivier”) response = get(“/api/users/1.json”) data =

    JSON.parse(response.body) ! expect(data). to include({ name: “Olivier”})
  27. RSpec says 1 example, 0 failures

  28. None
  29. Can I do that in Ruby?

  30. Can I ask a Hash: Do you include this other

    Hash, perchance?
  31. Let’s try.

  32. data.include?({ name: “Olivier”}) => false

  33. Nope.

  34. RSpec is neat.™

  35. user = create(:user, name: “Olivier”) response = get(“/api/users/1.json”) data =

    JSON.parse(response.body) ! expect(data). to include({ name: “Olivier”})
  36. rspec-expectations include matcher

  37. lib/rspec/matchers/built_in/include.rb:58

  38. None
  39. lib/rspec/matchers/built_in/include.rb:74

  40. You’re a Hash. 
 I’m a Hash. Let’s dance!

  41. lib/rspec/matchers/built_in/include.rb:58

  42. None
  43. None
  44. Is your value for this key the same as my

    value for this key?
  45. Warning Doesn’t work with nested hashes.

  46. Now, back to Hash.

  47. How does Hash#include? work?

  48. Hint: Not as neat.

  49. x = { a: true, b: false } ! y

    = { a: true } ! x.include?(y) => false
  50. Hash#include? == Hash#has_key?

  51. Hash#include? Hash#has_key? Hash#member? Hash#key?

  52. That’s weird.

  53. We value keys over values.

  54. Poor values are going to feel devalued.

  55. “ Principe of least astonishment If a necessary feature has

    a high astonishment factor, it may be necessary to redesign the feature.
  56. Is Hash#include? astonishing?

  57. String#include?

  58. x = "abc" => "abc" ! x.include?("a") => true !

    x.include?("d") => false ! x.include?("abc") => true
  59. Array#include?

  60. a = [1,2,3] => [1, 2, 3] ! a.include?(1) =>

    true ! a.include?(4) => false ! a.include?([1,2,3]) => false
  61. Answer: Hash#include? is a little astonishing, to me.

  62. None
  63. Maybe I can do something about it.

  64. None
  65. None
  66. None
  67. Lesson #1 ! My expectations and surprises are not universal.

  68. Lesson #2 ! Nobody wants to break the Ruby API.

  69. None
  70. Hope, at last!

  71. “Does this Hash contain this other Hash?”

  72. Hash#contain?

  73. x = { a: true, b: false } ! y

    = { a: true } ! x.contain?(y) => true
  74. Wouldn’t that be nice?

  75. Or Hash#subhash? like Set#subset?

  76. Along comes a Patch Monster

  77. Nobuyoshi Nakada @hone02

  78. None
  79. nobu made my idea real.

  80. Thank you nobu.

  81. Lesson #3 ! You don’t need to know C to

    contribute to Ruby.
  82. Lesson #4 ! There are many good humans in the

    community who will help you.
  83. What now?

  84. bugs.ruby-lang.org

  85. None
  86. Read the Wiki Read the Wiki (yes, it’s a little

    messy)
  87. None
  88. How to Request Features

  89. Meaningful improvement? 1

  90. Before Iterate over the hash or use a 
 side-effect

    of another method (hack) to the achieve expected result.
  91. After Ask hash if it contains another hash: it responds

    true or false. It’s an expressive and less surprising interface.
  92. New request? 2

  93. None
  94. None
  95. Not really.

  96. But different scope 
 & use case.

  97. And the issue hasn’t been followed-up on.

  98. 3 Can it be done another way?

  99. Yes, but verbose or inexpressive.

  100. 4 Would it benefit many people?

  101. None
  102. Seems like it.

  103. 5 Good name?

  104. Question: does hash contain other hash? ! Method: Hash#contain?

  105. So, yes.

  106. 6 Arguments?

  107. A hash.

  108. 7 Return value?

  109. A boolean.

  110. 8 Any risk of incompatibility?

  111. Nope, it’s brand new.

  112. 9 Write it.

  113. None
  114. But nobu’s patch is better.

  115. None
  116. 9 Make a concise but complete proposal.

  117. None
  118. I’m still working on it.

  119. Follow through. 10

  120. Will do.

  121. Let’s Rewind

  122. Find Inspiration 0

  123. Other People’s Feature Requests

  124. None
  125. None
  126. Documentation Patches

  127. None
  128. “ documenting-ruby.org Existing documentation could use some polish in form

    of clearer descriptions and better examples
  129. Docs are a great 
 place to start.

  130. None
  131. None
  132. Accepted Features

  133. None
  134. https://bugs.ruby-lang.org/projects/ruby-trunk/issues?query_id=94

  135. None
  136. There are quite a few unassigned ones.

  137. None
  138. Bugs!

  139. None
  140. Sounds less fun, but fixing bugs will definitely help.

  141. Feature requests are a tougher sell.

  142. Maintainers

  143. None
  144. None
  145. Talk to maintainers

  146. The Core Team is pretty busy, why not save them

    some work.
  147. Get Comfortable

  148. None
  149. Terence Lee

  150. None
  151. You’re not alone.

  152. None
  153. That’s my answer by the way.

  154. None
  155. None
  156. olivierlacan.typeform.com/to/WxL7Ql

  157. Science needs to meet reality before it becomes technology.

  158. This is were you come in.

  159. Your point of view matters.

  160. Your help is needed.

  161. status quo With a more diverse community the is more

    likely to be challenged.
  162. That’s how we make progress.

  163. Let’s make this Ruby sparkle!

  164. Thank you for caring. hi@olivierlacan.com