Skip to content

Conversation

@dhower-qc
Copy link
Collaborator

@dhower-qc dhower-qc commented Apr 1, 2025

Ruby, like most scripting languages, is not statically typed. While great for initial productivity, it can make changes challenging since errors are only caught at runtime, and only if that path is exercised.

There are two type checking solutions for Ruby: Sorbet and RBS/Steep. I tried both with the UDB code base. Based on that evaluation, I determined that Sorbet was higher quality, had much better documentation, and more mature. It's also in commercial use so is likely to be supported long-term.

Sorbet uses gradual type checking: you can add type signatures to subsets of the code, and Sorbet only checks what is known. Thus, we can start using it without annotating the entire code base up front.

This PR highlights the utility of the tool: it found several bugs already.

There is a cost to using Sorbet, mostly in terms of added development time

  • The signature syntax needs to be understood by developers.
  • Some extra [assertions]https://sorbet.org/docs/type-assertions are needed in code aside from the function signatures
    • Though I found the tool is surprisingly helpful in telling you exactly what assertion is needed (even with an autocorrect option)
       

Let's discuss more here, but based on this experiment my recommendation is that we merge this PR.

@dhower-qc dhower-qc changed the title Add Ruby typechecking with Sorbet and Tapioca [WIP] Add Ruby typechecking with Sorbet and Tapioca Apr 1, 2025
@dhower-qc dhower-qc marked this pull request as ready for review April 18, 2025 01:08
@dhower-qc dhower-qc changed the title [WIP] Add Ruby typechecking with Sorbet and Tapioca feat(ruby): add static type checking with Sorbet Apr 18, 2025
Copy link
Collaborator

@AFOliveira AFOliveira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me, aside from that small CSR which seems misplaced in the PR.

I do feel like the bar for contributing to UDB’s codebase is a bit higher than it needs to be. It seems difficult for folks who haven’t worked on the project before to make even small changes. I think that’s part of why there’s a lot of interest in UDB, but not as many people actively contributing. As long as we're around and maintaining it, things should be fine—but I do wonder if this might cause issues in the long run.

I don’t have strong opinions on this. I’m not familiar with Sorbet yet, but I’ll learn it. The fact that it’s not mandatory right now feels like a good way to ease into it.

Copy link
Collaborator

@ThinkOpenly ThinkOpenly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more of a rube than a Ruby programmer, but doesn't seem too bad, especially if adoption for new code is currently optional.

@dhower-qc dhower-qc enabled auto-merge April 30, 2025 02:13
The recommended way to handle rbi files for gems is to check them in.
However, since we use a container enviornment and can link to a verion of
hand-written rbis, we don't need to do this.
@dhower-qc dhower-qc added this pull request to the merge queue Apr 30, 2025
@dhower-qc dhower-qc removed this pull request from the merge queue due to a manual request Apr 30, 2025
@AFOliveira
Copy link
Collaborator

@dhower-qc should mip get his own issue?

@dhower-qc dhower-qc enabled auto-merge April 30, 2025 15:59
@dhower-qc dhower-qc added this pull request to the merge queue Apr 30, 2025
Merged via the queue into main with commit 6ab1548 Apr 30, 2025
17 checks passed
@dhower-qc dhower-qc deleted the sorbet branch April 30, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants