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

Types teaches success, what will we do?

Fu-ga
September 11, 2022

Types teaches success, what will we do?

at RubyKaigi 2022

Fu-ga

September 11, 2022
Tweet

More Decks by Fu-ga

Other Decks in Technology

Transcript

  1. RubyKaigi 2022 @Mie Center for the Arts Types Teaches success,

    what will we do? 2022.09.08(Thu) Fu-ga / ESM, Inc.
  2. Fu-ga @fugakkbn   Ruby on Rails engineer   Work at

    ESM, Inc.   gem_rbs_collection contributor   Interested in “Types” related technologies for Ruby
  3. ×

  4. None
  5. 🦐🍛

  6. None
  7. Speakers from ESM #rubykaigiB DAY1 14:10-14:40 @fugakkbn DAY2 11:30-12:00 @koic

    DAY3 14:50-15:20 @ima1zumi
  8. RubyKaigi 2022 @Mie Center for the Arts Types Teaches success,

    what will we do? 2022.09.08(Thu) Fu-ga / ESM, Inc.
  9. https://unsplash.com/photos/4V1dC_eoCwg

  10. Are Ruby type declarations in your project?

  11. Are Ruby type declarations in your project? 🙋‍♂️

  12. Few…🤔

  13. https://unsplash.com/photos/4V1dC_eoCwg

  14. Are you using TypeScript in your project?

  15. Are you using TypeScript in your project? 🙋‍♂️

  16. A lot!😆

  17. Feedback by types ✓Code complements ✓Type of arguments of method

    call ✓Suggestion of possible errors
  18. Improve convenience of development tools Improved developer experience Improved development

    efficiency Prevention of bugs🐛
  19. Types Types teaches teaches Success! Success! https://unsplash.com/photos/Ua-agENjmI4

  20. We want to benefit from types in Ruby https://unsplash.com/photos/nxy9wFUiksg

  21. We can now write static types in Ruby RBS, Steep

    Starting with Ruby 3.0, those are bundled with Ruby 💎 Can start small No impact on runtime No loss of writing comfort Product code and type definitions are separated
  22. So why is it so difficult? One reason comes to

    mind
  23. https://rubygems.org

  24. https://rubygems.org/stats

  25. https://rubygems.org/stats

  26. None
  27. None
  28. Directory with type definitions for gems

  29. None
  30. None
  31. 44 / about 173,000 😢

  32. Most gem type definitions are missing ✓Many projects rely on

    third-party gems ✓About 173,000 gems registered at rubygems.org ✓In contrast, gem_rbs_collection still has only about 40 gem type definitions😢
  33. https://unsplash.com/photos/JrZ1yE1PjQ0

  34. Proposal

  35. Proposal Let’s contribute to gem_rbs_collection!

  36. Centralized repository for gem type definitions ”DefinitelyTyped" in TypeScript More

    type definitions here are expected to make it easier to implement into projects.
  37. So... Step by step instructions on how to contribute to

    gem_rbs_collection Today's Theme
  38. Notice   I ’m a contributor and not the maintainer

    of   gem_rbs_collection   I'll speak based on my experience so far, but it   may differ from the maintainer's intentions RBS syntax is not discussed.
  39. https://github.com/ruby/rbs/blob/master/docs/syntax.md

  40. Steps to Steps to contribute to contribute to gem_rbs_collection gem_rbs_collection

  41. One Add or modify existing type definitions Two Add new

    gem type definitions
  42. One Add or modify existing type definitions Two Add new

    gem type definitions
  43. Steps to contribute Finding Finding missing or incorrect type definitions

    Check Check for mismatch between type definition and implementation Fix Fix the appropriate rbs file Patch Open a Pull Request
  44. None
  45. None
  46. None
  47. None
  48. 🤔

  49. None
  50. None
  51. Receive block!

  52. None
  53. None
  54. Not able to receive block

  55. None
  56. Pull Request: Add #count type definitions to activerecord

  57. None
  58. Just this

  59. Steps to contribute Finding Finding missing or incorrect type definitions

    Check Check for discrepancies between errors and implementation Fix Fix the appropriate rbs file Patch Open a Pull Request
  60. One Add or modify existing type definitions Two Add new

    gem type definitions
  61. One Add or modify existing type definitions Two Add new

    gem type definitions
  62. Two more cases ✓Automatic and exhaustive generation ✓Add only some

    of them
  63. Two more cases ✓Automatic and exhaustive generation ✓Add only some

    of them These steps are almost identical, differing only in the way the RBS is defined
  64. https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

  65. https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md Steps are shown here

  66. Step.1 Setup environment

  67. None
  68. Run `bundle install`

  69. Step.2 Generate a boilerplate

  70. None
  71. None
  72. None
  73. None
  74. None
  75. None
  76. None
  77. None
  78. Step.3, 4 Write RBS files & tests

  79. Assumption: Not necessarily all APIs need to have type definitions

  80. " Writing high-quality type definitions are difficult. Focus on examples

    available through the README or docs of the gem. Focus on the APIs your app is using. https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md
  81. Partitive Exhaustive

  82. Partitive

  83. for example amatsuda/active_decorator

  84. None
  85. None
  86. Pull Request: RBS for ActiveDecorator gem

  87. None
  88. None
  89. None
  90. None
  91. None
  92. None
  93. None
  94. None
  95. None
  96. Merged! Merged!

  97. Partitive Exhaustive

  98. Exhaustive

  99. for example brainspec/enumerize

  100. None
  101. None
  102. Command to generate RBS

  103. source files

  104. destination file

  105. None
  106. Most are `untyped`

  107. None
  108. None
  109. PATCH IT! PATCH IT!

  110. None
  111. None
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~~

  113. ~~~~~~~~~~~~~~~~~~~~~~~~~~ Write all?🤔 Write all?🤔

  114. " Writing high-quality type definitions are difficult. Focus on examples

    available through the README or docs of the gem. Focus on the APIs your app is using. https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md
  115. Pull Request: Add RBS for Enumerize gem

  116. None
  117. Partitive Exhaustive

  118. Partitive Exhaustive How should we use How should we use

    them differently? them differently?
  119. ✓If you want a tight type definition for a particular

    method ✓If you want RBS for now 👉Partitive 👉Exhaustive
  120. Step.5 Open a Pull Request

  121. Before that...

  122. None
  123. None
  124. rbs validate steep check

  125. And then Open your Pull Request!😄

  126. F Y I 💁‍♂️ For your information

  127. FYI REMOVE manifest.yml The file manifest.yml is necessary if there

    are dependencies that are not described in Gemfile.lock or gemspec. If there are no dependencies, remove it before opening PR NOT ALL GEMS ARE COVERED Standard and built-in library RBS files are available in the ruby/rbs repository
  128. None
  129. None
  130. None
  131. None
  132. None
  133. None
  134. None
  135. None
  136. None
  137. None
  138. https://unsplash.com/photos/4V1dC_eoCwg

  139. WHAT WANTED TO TELL Let's actively use RBS, Steep and

    share our knowledges I hope that the Ruby type ecosystem will develop further
  140. None