1. 19
  1. 2

    Can anyone who’s tried sorbet comment on why you’d want to use this instead of crystal?

    1. 10

      your question is ‘why x instead of y’, but these two are not direct competitors/alternatives, though both are related to ‘type checking ruby(-esque) code’.

      sorbet is a ‘checker’ that can be used on top of an existing ruby codebase, which also means it can be gradually adopted. this is similar to mypy in the python world.

      crystal, on the other hand, is a separate (though similar looking) programming language with no direct interop with the ruby ecosystem. instead, it compiles to machine code, as opposed to running inside a ruby interpreter/vm.

      1. 1

        yeah crystal is like elixer… similar syntax but distinctly different and incompatible.

        1. 1

          Thanks. “Ability to gradually migrate” does answer the question

        2. 4

          completely different languages and runtimes?

          it’s my understanding that sorbet, and the new type checking functionality built in to ruby 3 using RBS can be implemented gradually in existing ruby projects

          crystal would require a rewrite

          1. 1

            I am more interested in that exactly: What have people’s experiences been between RBS and Sorbet? They seem to approach the same problem, but I suspect they’re not entirely overlapping. As such, I find myself wanting to gather the experiences of someone who has tried both before deciding which I might gradually introduce into a project.

            1. 6

              I wrote an online poker virtual table in ruby without any typechecking at the start of the pandemic. It went swimmingly.

              After playing for a few weeks I realized about a dozen tweaks I wanted to make. Diving back into the code was a little difficult and I grabbed Sorbet (my first go at it) and I found it really helped me keep things straight. I used the types sparingly at first, mainly to document my assumptions about parameters for certain functions. In some places the type signatures got complicated and I took that as a hint to refactor. Decent experience all around. The worst part was the way it loaded gems when probing for type signatures in my dependencies. Thankfully that was a smaller project, probably 2k LoC with a half dozen dependencies. I can’t imagine how a large rails application would fare in that process.

              Later RBS was released and I figured I’d port my game over to it since the official nature of RBS seemed to challenge Sorbet and the future might demand I make the change. I didn’t like any part of it. The definitions being in a separate file was probably the worst. It meant that those useful notes about my assumptions (in the form of type signatures) were an extra step away. The error messages coming from the Steep tool were significantly less understandable than the Sorbet messages. It ran slower in most cases too.

              My current day job doesn’t use ruby but if it did I wouldn’t necessarily advocate for my team to adopt either tool. If someone else did, I’d be happy to help bring in Sorbet and I would argue strongly against RBS. The experience of no type checking was better than RBS.

              1. 1

                Thanks for sharing your experiences! I’ll probably try out Sorbet first on a smaller project, and get a feel for it.