An Overview of Type Checking in Ruby with Sorbet, by Emily Samp
Description
For 30 years, Ruby has been known as a dynamic programming language that allows–and even encourages–practices like duck typing and metaprogramming. While a dynamic language gives programmers a lot of flexibility, it can also make programs hard to reason about and hide errors that only become apparent once code is running in production.
Enter Sorbet: a gradual type checker for Ruby. Using Sorbet, we can harness the flexibility and creativity of a dynamic language while benefiting from the safety of typing.
In this talk, we’ll learn about the pitfalls of programming with dynamic languages such as Ruby and see how a tool like Sorbet can help us avoid them. We’ll learn what Sorbet is and dive into how it works. Finally, we’ll see how Sorbet functions at scale by examining how Shopify uses typed Ruby in production.
Notes
Intended Audience
This talk is intended for developers of all experience levels who are interested in static typing and coding languages. No prior knowledge of static typing or Ruby will be required to understand the talk.
Talk Outcomes
By the end of this talk, the audience should be able to answer the following questions:
- What is gradual typing?
- Why add type checking to the Ruby language instead of using a statically typed language?
- What is Sorbet, and how does it work?
- What are the benefits of adopting Sorbet in a Ruby codebase?
Outline
- Introduction [3 minutes]
- Ruby [5 minutes]
- Brief introduction to Ruby and its history
- Explanation of dynamic languages and duck typing
- Typing [7 minutes]
- What is gradual typing?
- What is static type checking? What is runtime type checking? How can they be used together?
- What problems can be solved by typing?
- Why use Ruby with types instead of a statically typed language?
- Bonus: Static typing can enable code editor tools (e.g. go-to-definition, code completion, and replace all) which are common in other languages but lacking in Ruby.
- Sorbet [15 minutes]
- Brief introduction to Sorbet and its history
- Talk about gradual typing
- Demonstrate how to adopt Sorbet in an existing Ruby app
- Show how Sorbet solves the problems we discussed in section 3
- Sorbet implementation and architecture [15 minutes]
- How does Sorbet analyze our Ruby code to identify types statically and at runtime?
- What makes Sorbet’s static type checker so fast?
- Sorbet at Shopify [5 minutes]
- At Shopify, we've been using Sorbet since 2019
- We have four years worth of survey data on the use and perception of Sorbet
- Share how Sorbet improves the development experience at Shopify
- Talk about areas for improvement
- Conclusions [5 minutes]
- Recap the main points of the talk and ask audience to consider whether Ruby with Sorbet might be a good tool for them
Pitch
For the past year, I have been working on a team at Shopify that helps other teams add and maintain Sorbet in their Ruby projects. I have seen the positive impact that Sorbet has had on Ruby developers at Shopify and in the broader Ruby community, and I've learned a lot about compilers and static type checking along the way! This talk would present a unique opportunity to share some of the cutting-edge work happening in the Ruby community with the KCDC audience, making it a valuable addition to the program.