Stripe uses Sorbet to type check our 15 million lines of Ruby code, making engineers more productive. Here's why we love Sorbet.
Overview
Sorbet is Stripe's open-source type checker for Ruby, designed to enhance code clarity and productivity in a large codebase. It enables rapid type error feedback and improves the understanding of code relationships, addressing challenges faced by engineers in a dynamically typed language.
What You'll Learn
1
How to use Sorbet to improve code clarity in Ruby projects
2
Why type annotations can prevent common coding errors in Ruby
3
When to implement Sorbet in a Ruby codebase for maximum productivity
Prerequisites & Requirements
- Familiarity with Ruby programming language and its dynamic typing
- Basic understanding of type checkers and their benefits(optional)
Key Questions Answered
How does Sorbet enhance productivity in Ruby development?
Sorbet provides near-instantaneous feedback on type errors, allowing engineers to understand code relationships quickly. With 80% of edits receiving feedback in milliseconds, it significantly reduces the time spent debugging and enhances overall productivity in large Ruby codebases.
What are the cultural impacts of adopting Sorbet at Stripe?
Adopting Sorbet has reinforced engineering norms at Stripe, such as improving reliability and ensuring public interfaces have up-to-date documentation. The use of type annotations has become a reflexive practice among engineers, leading to fewer production errors and better code quality.
What challenges does Ruby's dynamic typing present?
Ruby's dynamic typing can lead to difficulties in understanding code due to features like lack of import statements, extensive use of modules, and metaprogramming. These factors can obscure method definitions and complicate code navigation, which Sorbet aims to alleviate.
How does Sorbet compare to other type checkers like Flow?
While Flow is a static type checker for JavaScript, Sorbet was developed specifically for Ruby to address its unique challenges. Sorbet offers faster type checking and integrates seamlessly with Ruby's features, unlike other type checkers that may not be optimized for Ruby's dynamic nature.
Key Statistics & Figures
Lines of code in Stripe's Ruby codebase
15 million
Sorbet currently runs over Stripe's entire Ruby codebase, which consists of 15 million lines of code spread across 150,000 files.
Percentage of non-test files using strict typing
85%
After four years of using Sorbet, 85% of all non-test files in Stripe's codebase opt into # typed: strict.
Speed of type error feedback
80%
Sorbet can finish reporting type errors in milliseconds for 80% of edits, even in a multi-million line codebase.
Technologies & Tools
Some links below are affiliate links. We may earn a commission if you make a purchase.
Backend
Sorbet
Type checker for Ruby, enhancing code clarity and productivity.
Backend
C++
Programming language used to develop Sorbet for high performance.
Backend
Webassembly
Allows Sorbet to be tried out in the browser.
Key Actionable Insights
1Implement Sorbet in your Ruby projects to enhance code quality and reduce errors.By integrating Sorbet, teams can benefit from immediate feedback on type errors, which helps in maintaining high code standards and reduces the likelihood of bugs in production.
2Encourage the use of type annotations among your engineering team.Type annotations not only improve code clarity but also serve as documentation, making it easier for new engineers to understand the codebase and for existing engineers to maintain it.
3Utilize Sorbet's features to navigate complex Ruby codebases effectively.Sorbet's powerful editor integration allows developers to quickly find method definitions and understand their usage, which is crucial in large and intricate Ruby applications.
Common Pitfalls
1
Overlooking the importance of type annotations can lead to increased errors in production.
Without type annotations, developers may introduce bugs that are difficult to trace, as dynamic typing allows for more ambiguous code. Encouraging the use of Sorbet can help mitigate this risk.
Related Concepts
Type Checking In Dynamically Typed Languages
Best Practices For Ruby Development
Static Vs Dynamic Typing