4 ms·
It's been a sec since I've used Ruby. How's the typing story? Seems like Sorbet is doing quite well, but are there comprehensive typings for the ecosystem, like
by hardwaregeek 4y ago
It's been a sec since I've used Ruby. How's the typing story? Seems like Sorbet is doing quite well, but are there comprehensive typings for the ecosystem, like TypeScript? Because with ergonomic, comprehensive type checking and a JIT, Ruby might be a tempting option again.
- jrochkind1 4y agoNo, I'm afraid I'd say Sorbet/RBS haven't really been catching on widely.
- sitkack 4y agohttps://sorbet.org/blog/2020/07/30/ruby-3-rbs-sorbet https://sorbet.org/blog/2020/07/30/ruby-3-rbs-sorbet looks really cool. You know the yjit folks are going to take this and make yjit even faster right?
- treis 4y agoThe problem, I think, is the restrictions that not having a compilation step places on what typing you can do without a big breaking change. Typescript didn't have this problem because everyone already used bundlers/minifiers/etc. Adding another compiler like step to that process was pretty natural. Ruby doesn't have that and adding it in poses problems for REPL development. They chose to go with a separate file for types. Which gets around the breaking change problem but the ergonomics are terrible. Think the hope is that IDE support eventually gets around that issue. But thus far not a whole lot of adoption.
- letmeinhere 4y agoSure, this is an advantage that Typescript has, but it doesn't explain Ruby's lagging progress compared to Python and PHP. Some of that can probably pinned on the greater dynamism of Ruby, making all manner of static analysis quite challenging. But from what I've seen, it seems like the main reason is indifference or even mild hostility from the language maintainers. It looks a lot like they saw Sorbet taking off and slapped together a competing spec (without any associated tooling) that would ensure all type information stays outside of the `.rb` file. It seems like the only impact it has had is to dissuade people who would like some static types from adopting it, in favor of this vaporware. Contrast this with Python's embrace gradual extension of mypy type hints. I'd love to be proven wrong, that there are thriving projects building atop RBS. I'd still _prefer_ a system that allowed me to type a function signature so that anyone inspecting it could immediately know its shape, but at least the shadow types would be _something_.
- michaelcampbell 4y agoI've seen more than one ruby dev proclaim they specifically don't want types; if you want a language that has it, there are plenty to choose from. My take here is that typed-ruby is something SOME people want (I'm one), but a lot don't. I'm not sure what level of force that provides to anyone who has either tried or is considering adding it to the language.
- treis 4y agoI agree that Sorbet is a better solution but it's also a breaking change. It's a relatively small breaking change and, IMHO, would have been more than worth it but alas it was not my decision to make.
- jacobsenscott 4y agoSpeaking for sorbet - no compilation step is a feature, not a bug. Imagine adding some kind of build step to every ruby app out there! Sorbet annotations are just valid ruby code you add to your files (you don't need to write separate type files - the sorbet system might do this for you though). Sorbet also provides a gradual typing system where you can start adding types to a large code base and gradually make the checking more strict. Stripe claims to be using it on a huge ruby code base and that their developers generally like it. However I think many devs don't want static types on Ruby. We like our duck typing!
- bboylen 4y agoCouldn't you still have duck typing? If a method expects to be passed an argument that it can call "quack" on, can't you define a type that has "quack"? The actual argument could be a Duck or a Goose but as long as it has a "quack" method the type will be OK I haven't used types in Ruby (or much at all other than dabbling in Typescript), so I might be missing something
- reducesuffering 4y agoRuby's typing story is still the worse-than-modern-Java boilerplate of writing loads of unit tests just to make sure an object is the type that you think it is.
- fxn 4y agoThis is not true. In Ruby, tests are the same you'd write in any other language. You test that things do what they are supposed to do, not the types of parameters or return values.
- bobbylarrybobby 4y agoOk but if you can't constraint the types passed to a function then the universe of objects you have to test is massive. For instance you may have a performance benchmark that checks that a certain operation runs in a certain big O -- say, you want to make sure a contains(collection, elem) functions runs in constant time. If you can't constrain the type of collection (to be some kind of Map, say) then you are left testing that all paths that call contain do so with a Map and not, say, a List. In a typed language the type system would ensure that for you.
- sdf4j 4y agoThat example is not very grounded on reality, isn't it?
- semiquaver 4y agoTry sorbet in a real project before you make this claim. It’s not perfect but it’s pretty good.
- deleted 4y ago[deleted]
- faitswulff 4y agoThis thread on Rubyists' impressions of the gradual typing options is relevant: https://www.reddit.com/r/ruby/comments/105sdax/whats_the_latest_on_static_typing/ https://www.reddit.com/r/ruby/comments/105sdax/whats_the_lat... Spoiler alert: not a lot of fans
- semiquaver 4y agoMatz poisoned the well once sorbet was gaining traction by releasing a nearly useless competitor (RBS) and refusing to allow any interop.