Slide 1

Slide 1 text

RubyKaigi 2022 @Mie Center for the Arts Types Teaches success, what will we do? 2022.09.08(Thu) Fu-ga / ESM, Inc.

Slide 2

Slide 2 text

Fu-ga @fugakkbn   Ruby on Rails engineer   Work at ESM, Inc.   gem_rbs_collection contributor   Interested in “Types” related technologies for Ruby

Slide 3

Slide 3 text

×

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

🦐🍛

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Speakers from ESM #rubykaigiB DAY1 14:10-14:40 @fugakkbn DAY2 11:30-12:00 @koic DAY3 14:50-15:20 @ima1zumi

Slide 8

Slide 8 text

RubyKaigi 2022 @Mie Center for the Arts Types Teaches success, what will we do? 2022.09.08(Thu) Fu-ga / ESM, Inc.

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Are Ruby type declarations in your project?

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Few…🤔

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Are you using TypeScript in your project?

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

A lot!😆

Slide 17

Slide 17 text

Feedback by types ✓Code complements ✓Type of arguments of method call ✓Suggestion of possible errors

Slide 18

Slide 18 text

Improve convenience of development tools Improved developer experience Improved development efficiency Prevention of bugs🐛

Slide 19

Slide 19 text

Types Types teaches teaches Success! Success! https://unsplash.com/photos/Ua-agENjmI4

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

So why is it so difficult? One reason comes to mind

Slide 23

Slide 23 text

https://rubygems.org

Slide 24

Slide 24 text

https://rubygems.org/stats

Slide 25

Slide 25 text

https://rubygems.org/stats

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Directory with type definitions for gems

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

44 / about 173,000 😢

Slide 32

Slide 32 text

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😢

Slide 33

Slide 33 text

https://unsplash.com/photos/JrZ1yE1PjQ0

Slide 34

Slide 34 text

Proposal

Slide 35

Slide 35 text

Proposal Let’s contribute to gem_rbs_collection!

Slide 36

Slide 36 text

Centralized repository for gem type definitions ”DefinitelyTyped" in TypeScript More type definitions here are expected to make it easier to implement into projects.

Slide 37

Slide 37 text

So... Step by step instructions on how to contribute to gem_rbs_collection Today's Theme

Slide 38

Slide 38 text

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.

Slide 39

Slide 39 text

https://github.com/ruby/rbs/blob/master/docs/syntax.md

Slide 40

Slide 40 text

Steps to Steps to contribute to contribute to gem_rbs_collection gem_rbs_collection

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

🤔

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Receive block!

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Not able to receive block

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Pull Request: Add #count type definitions to activerecord

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Just this

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

Step.1 Setup environment

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Run `bundle install`

Slide 69

Slide 69 text

Step.2 Generate a boilerplate

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

Step.3, 4 Write RBS files & tests

Slide 79

Slide 79 text

Assumption: Not necessarily all APIs need to have type definitions

Slide 80

Slide 80 text

" 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

Slide 81

Slide 81 text

Partitive Exhaustive

Slide 82

Slide 82 text

Partitive

Slide 83

Slide 83 text

for example amatsuda/active_decorator

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

Pull Request: RBS for ActiveDecorator gem

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

Merged! Merged!

Slide 97

Slide 97 text

Partitive Exhaustive

Slide 98

Slide 98 text

Exhaustive

Slide 99

Slide 99 text

for example brainspec/enumerize

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

Command to generate RBS

Slide 103

Slide 103 text

source files

Slide 104

Slide 104 text

destination file

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

Most are `untyped`

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

PATCH IT! PATCH IT!

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

~~~~~~~~~~~~~~~~~~~~~~~~~~

Slide 113

Slide 113 text

~~~~~~~~~~~~~~~~~~~~~~~~~~ Write all?🤔 Write all?🤔

Slide 114

Slide 114 text

" 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

Slide 115

Slide 115 text

Pull Request: Add RBS for Enumerize gem

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

Partitive Exhaustive

Slide 118

Slide 118 text

Partitive Exhaustive How should we use How should we use them differently? them differently?

Slide 119

Slide 119 text

✓If you want a tight type definition for a particular method ✓If you want RBS for now 👉Partitive 👉Exhaustive

Slide 120

Slide 120 text

Step.5 Open a Pull Request

Slide 121

Slide 121 text

Before that...

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

rbs validate steep check

Slide 125

Slide 125 text

And then Open your Pull Request!😄

Slide 126

Slide 126 text

F Y I 💁‍♂️ For your information

Slide 127

Slide 127 text

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

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

No content

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

No content

Slide 135

Slide 135 text

No content

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

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

Slide 139

Slide 139 text

WHAT WANTED TO TELL Let's actively use RBS, Steep and share our knowledges I hope that the Ruby type ecosystem will develop further

Slide 140

Slide 140 text

No content