Type checkers
What is Sorbet? An introduction to Stripe's gradual type checker for Ruby
Sorbet is a fast, gradual static type checker designed for Ruby and built at Stripe. It analyzes a project before the code runs and reports type errors in seconds. Because it is gradual, it can be adopted incrementally, one file at a time.
- Tool
- Sorbet
- Made by
- Stripe
- Official site
- sorbet.org
- Category
- Type checkers
Who makes Sorbet
Sorbet is built at Stripe, where most code is Ruby. That origin explains its focus: it is a type checker designed for Ruby and shaped around working with ordinary Ruby codebases.
The official website is linked below.
Official website: sorbet.org
What Sorbet is for
Sorbet is for finding type errors in Ruby code without running it. The command-line tool statically analyzes a project before the code runs, and it is multithreaded so that type errors are reported in seconds.
It also provides a runtime counterpart. The sorbet-runtime gem checks types dynamically at runtime, which complements the static analysis done by the command-line tool.
Explicit signatures also help readers of the code, not only its author. A signature documents what a method expects and returns, which makes unfamiliar code easier to follow.
Who Sorbet is for
The vendor does not state a specific audience. The facts describe Ruby teams that want types without abandoning existing code: Sorbet works with normal Ruby and allows adoption one file at a time.
Developers can opt into stricter static checks, so a team can start loosely and tighten the rules where it makes sense. Teams that run continuous integration will note that Sorbet is easy to add to CI.
Notable capabilities
Sorbet pairs a fast command-line checker with editor support and a gradual adoption model. The documented capabilities are:
- Multithreaded checking: Sorbet reports type errors in seconds.
- Gradual adoption: it is a gradual type checker that enables incremental adoption, one file at a time.
- Opt-in strictness: developers can choose stricter static checks as they go.
- Control-flow-sensitive typing: it uses this approach instead of requiring annotations everywhere.
- Backwards-compatible signatures: it is compatible with Ruby and adds signature syntax that remains backwards-compatible.
- Gem type definitions: Sorbet reads a project's Gemfile to produce type definition files for its gems.
- Editor integration: editor features are provided through the Language Server Protocol.
- Runtime checking: the sorbet-runtime gem also checks types dynamically at runtime.
How Sorbet fits type checkers
Among type checkers, Sorbet is the one built specifically for Ruby. It does not introduce a new language; it works with normal Ruby and adds signature syntax that is backwards-compatible with it.
Setup involves adding gems, initializing Sorbet and running the type check. From there it can run in CI and in editors, which places it alongside other automated checks in a development workflow.
In Linthelm's wider niche of linters, static analysis and code quality, Sorbet covers the type-correctness layer for Ruby projects. Where a linter looks for patterns and style issues, a type checker verifies how values flow through code, and Sorbet does so statically before the program runs.
Frequently asked questions
What is Sorbet used for?
Sorbet is used to type check Ruby code. Its command-line tool statically analyzes a project before the code runs and reports type errors in seconds.
Who develops Sorbet?
Sorbet is built at Stripe, where most code is Ruby.
Do I have to add types to an entire Ruby project at once?
No. Sorbet is a gradual type checker that works with normal Ruby and allows adoption one file at a time.
Does Sorbet work in editors?
Yes. Editor integration uses the Language Server Protocol.
Does Sorbet check types at runtime?
The sorbet-runtime gem also checks types dynamically at runtime, in addition to the static analysis performed by the command-line tool.
Linthelm is independent and is not affiliated with Stripe. Product names belong to their owners. Features change; confirm details on the official website.