Live data from Hacker News

Static Typing for Ruby: Adopting Sorbet at Scale

shopify.engineering

11–20 of 72 posts

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#11
At this point Ruby (which is still slow and dynamic compared to most other faster languages) looks like a sunk cost.

Only reason why it's still alive is Rails, I don't see much hope for it longer term, Crystal and Elixir does IMO.

Using Ruby/Sorbet screams using JS/Flow to me, instead of using a language with types built in.

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#13
What makes Ruby so irreplaceable? Why struggle to make it something it's not when you could pick an existing statically typed language and build your system? Also how is Ruby a safe language for financial transactions when an engineer can hijack a running process and change memory without leaving a trace

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#14

At this point Ruby (which is still slow and dynamic compared to most other faster languages) looks like a sunk cost. Only reason why it's still alive is Rails, I don't see much hope for it longer term, Crystal and Elixir does IMO. Using Ruby/Sorbet screams using JS/Flow to me, instead of using a language with types built in.

> At this point Ruby (which is still slow and dynamic compared to most other faster languages) looks like a sunk cost.

Can you expand on why you think this is?

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#15
post #12
post #5

Isn't crystal lang trying to do the same thing? Why not join forces?

Like others have stated in the thread, Crystal is a different language that shares some its syntax with Ruby. Our aim is to keep our Ruby codebase but adopt static types gradually.

Is there any runtime performance gain to be had in the interpreter at runtime when adding types. I understand the benefits to your workflow but is there an opportunity to allow the interpreter to do less work when types are used?

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#16
post #9
post #3

Earlier quoted context omitted.

Happy to answer any questions here about our process, results or tools!

Having used Sorbet, one thing immediately noticeable is that it's incredibly verbose due to needing to be valid ruby syntax. Was there any developer pushback on that? Also, maybe I missed it, but Sorbet has a very fleshed out plugin for VSCode but that's about it. How was the experience getting people who don't use VSCode to integrate it into their workflow?

There was definitely some general suspicion when we first introduced Sorbet. However, there were also some early adopters who didn't mind the syntax but really wanted the benefits. That's why we didn't push for types adoption, we allowed teams to adopt (or not) at their own pace. Once people saw the benefits, they wanted more of it. Syntax also stopped being a huge concern.

Quoting from the blogpost:

> - Developers get used to Sorbet syntax over time

> ...

> Our main observation is that developers enjoy Sorbet more as the typing coverage increases.

On the editor integration, the funny thing is that VSCode is the only editor that needs a special extension to integrate with Sorbet. The way Sorbet supports editors is via the built-in Language Server Protocol (LSP) mode which can be used with any LSP plugin for any editor. I know people who are using it with Vim, Sublime Text, etc. Integration is, in a nutshell, running `srb tc --lsp` as a subcommand and piping data in/out via stdin/out. Our tool Spoom actually uses the same LSP mode to provide extra developer tools and analysis on top of Sorbet.

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#17

What makes Ruby so irreplaceable? Why struggle to make it something it's not when you could pick an existing statically typed language and build your system? Also how is Ruby a safe language for financial transactions when an engineer can hijack a running process and change memory without leaving a trace

What makes millions of lines of code and decades of knowledge irreplaceable?

Is there any language or ecosystem that can protect against a rogue employee?

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#18
This looks great in general, but does anyone else find Sorbet's signature formulation offputting? Feels cluttered and not at-a-glance readable.

> sig {params(name: String, id: String).returns(Integer)}

My ruby isn't quite good enough to parse the language constructs that make up that line, but it's not pretty. I guess....sig is a class method which takes a block....and params is a class method (Added to BasicObject or something, perhaps?) to which you can pass any number of keyword params, and which returns an object that has a return method, to which you can pass any object type. I guess I don't know why you need to call sig at all, as opposed to just params( args ).returns( type ). I also have no idea how the sig call gets associated with the method that follows it.

I just wonder if there was a cleaner way to phrase this that's still syntactically viable.

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#19

What makes Ruby so irreplaceable? Why struggle to make it something it's not when you could pick an existing statically typed language and build your system? Also how is Ruby a safe language for financial transactions when an engineer can hijack a running process and change memory without leaving a trace

> hijack a running process and change memory without leaving a trace

Doesn't sound like a Ruby problem.

Re: Static Typing for Ruby: Adopting Sorbet at Scale

#20
post #5

Isn't crystal lang trying to do the same thing? Why not join forces?

> Isn't crystal lang trying to do the same thing?

Nope, Crystal is a statically-typed language with distinctly different than Ruby semantics that features Ruby-ish syntax.

Sorbet is an optional static type system for Ruby.

They aren't trying to do the same thing. One is trying to appeal to the aesthetic preferences of developers who like Ruby with static typing, the other is trying to enhance the Ruby ecosystem with static typing. There's only a superficial similarity between these things.

Post reply on HN