Skip to content
loading...

Sorbet (Ruby type checker) seems really neat!

ben profile image Ben Halpern twitter logo github logo ・1 min read  

Sorbet first came on the scene almost a year ago, so this post isn't really news.

But having not really gone into depth about how it actually works, I really enjoyed this podcast episode about how it works.

play pause Software Engineering Daily

Basically it is a gradual typing system designed for uneven adoption because that is what was needed at Stripe, and this makes it really appealing to adopt on an as-needed basis in a codebase based on individual team preferences and problems.

GitHub logo sorbet / sorbet

A fast, powerful type checker designed for Ruby

Sorbet logo

Sorbet

This repository contains Sorbet, a fast, powerful typechecker designed for Ruby It aims to be easy to add to existing codebases with gradual types, and fast to respond with errors and suggestions.

This README contains documentation specifically for contributing to Sorbet. You might also want to:

If you are at Stripe, you might also want to see http://go/types/internals for docs about Stripe-specific development workflows and historical Stripe context.

Table of Contents

The whole thing seems quite well thought out and useful, and the pattern of starting with type-free Ruby for prototyping and then moving to typing once business logic starts to congeal seems great.

twitter logo DISCUSS (4)
Discussion
markdown guide
 

I like the idea of bringing a Typechecker to Ruby in the way Sorbet does it because it doesn't feel intrusive (like TypeScript in JS, i.e). However, last year I gave it a try in a Rails project and couldn't make it work :sweat-smile:

Maybe in a couple of months would try again and see what happens :)

 

We had a good talk at our monthly Ruby meetup about it a while back. The tl;dr was that it’s promising but still (too much) effort. Also worth remembering that Matz has always been a bit critical about the idea, so it remains to be seen what an official solution will look like.

I did a write up a while back:

 

I've been using it on production for some time and I've both loved and hated it at some points.

The benefits it brings if your domain can benefit from types are good, but it still has some cons that are a bit problematic and that make using it more boilerplatey than other type systems like TypeScript for example.

The type system it provides is still not 100% ready and things like generics are there but they are not even documented. Support for rails exists but it isn't simple or comfortable to use. You need to regenerate the typings when you do things like add new models, controllers, routes, relations... That has an obvious cost, not only on the extra work it requires but also because onboarding someone new to the team is more complex.

The code in sorbet moves super fast and you need to upgrade it quite constantly if you don't want to be left behind. Sometimes upgrades are smooth, but some others you'll just suffer bugs and instabilities of different types (non-compatible gems, issues depending on the Ruby version...) they are fixed quite fast though, which is something to be grateful for.

In general, my impression over it is that it is not as ready as I would have liked to.

 

Been working with Sorbet for the past couple months, and overall it's been a good learning experience for me, and contributed to helping us produce more explicit code. I wrote some thoughts about the experience a little while ago: dev.to/nexmo/insights-from-incorpo...

Classic DEV Post from Jul 26 '19

🎩 JavaScript Enhanced Scss mixins! 🎩 concepts explained

In the next post we are going to explore CSS @apply to supercharge what we talk about here....

Ben Halpern profile image
A Canadian software developer who thinks he’s funny. He/Him.