Live data from Hacker News

RBS, Ruby’s new type signature language

developer.squareup.com

81–90 of 340 posts

Re: RBS, Ruby’s new type signature language

#81
post #50
post #16

Can someone explain why the types cannot live in Ruby code itself (after an appropriate version bump)? Python 3 incorporated types into the language itself, in a similar way (though non-reified) to PHP. This seems much easier to deal with than requiring two files (.rb and .rbs) to describe a single data structure.

Because Matz won't let people add type annotations to the ruby grammar.

Which is great.

Re: RBS, Ruby’s new type signature language

#82
post #2

Interesting. I’m surprised they didn’t opt to do this inline with the rest of the ruby code, because now they can diverge from each other. It’s a bit like a separate header file in C/C++/Obj-C, except in those cases the compiler will yell at you if the implementation doesn’t match the header. Having it blow up at runtime instead doesn’t feel like such a big change from the way it is now, other than helping out IDEs.

> I’m surprised they didn’t opt to do this inline with the rest of the ruby code, As they mention in the post, they followed typescript's approach, here. The benefit is it allows you to layer in typing into an existing codebase in a non-disruptive way.

> As they mention in the post, they followed typescript's approach, here.

They didn't, though! That's what's confusing me. TypeScript has inline types. .d.ts files are typically for JavaScript files that don't have types embedded.

Re: RBS, Ruby’s new type signature language

#83
post #29

Earlier quoted context omitted.

Remember this is designed by companies that already have existing, large, ruby codebases. For them, it makes a lot of sense to be able to incrementally add typing without having to make changes to the underlying code itself.

You can do both. Python allows for external .pyi files, for situations where you can't modify the underlying library (for example: it's written in C). There are tons of them: https://github.com/python/typeshed , but you can still add types to new code inline.

You can, but clearly the people designing this system have weighed the pros and cons and found that there would be more benefits to them to leave the source code unchanged.

Re: RBS, Ruby’s new type signature language

#84
post #71

It's worth noting that while the article is coming from Square, this is an official Ruby project and is "Ruby 3’s new language for type signatures". https://github.com/ruby/rbs

Yeah, I was wondering why this was being announced on Square's website. Seems it's because Square happens to employ Soutaro Matsumoto, who wrote the post and is also the creator of Steep[0] (an implementation of a typechecker for RBS files). It's not clear to me whether Soutaro is a member of the Ruby core team, so it feels a bit odd that the post is written like an announcement from the Ruby maintainers. [0] https:/…

Soutaro is indeed a code member of the Ruby team, he also happens to work at Square. Soutaro is also one of the main contributors to RBS and helped define that standard.

He was going to keynote on this at RubyKaigi this year until it was cancelled, and had a talk at RubyConf as well on this.

Re: RBS, Ruby’s new type signature language

#85
I haven't used Ruby in ages but this seems like a really odd way to incorporate type hints in the language.

I much prefer the Python 3+ approach of type annotations in source code.

I can't imagine having to look at a separate file just to figure out what the type of something is. You may say "tooling will fix this" but it's just far less overhead for everyone at the end of the day to just make annotations in source.

My more existential question is, is there really an advantage to doing static type checking in Ruby?

When I was doing Ruby, the way you can change objects on the fly, add methods on the fly, the vast amounts of metaprogramming, are types at "compile" (I know, not really) time really the same as types at runtime?

Like, it might be nice to get some autocomplete, but AFAIK tools already do that (RubyMine, others).

Re: RBS, Ruby’s new type signature language

#87
post #40

Anyone know, or have a guess, what RBS stands for? I'm not finding it in the article or library.

I'm seeing the type annotations being referred to as "signatures" in a couple of places. (R)u(B)y (S)ignatures seems like a reasonable guess.

That would be correct.

Re: RBS, Ruby’s new type signature language

#88

I wonder if this type information can be used by the vm to improve performance?

Matz had mentioned this as a key reason he was interested in working on this, as well as a "language server" with a lot of really interesting features like what JS/TS has with VS Code.

I had the good fortune to hear him talk about it at length at a conference a while ago and there's all types of fun stuff on the way.

Re: RBS, Ruby’s new type signature language

#89
post #48

I absolutely hate this. Separate files for types with no inline annotations possible? What an embarrassing compromise. This is all because Matz explicitly won't allow type signatures in .rb files. I wonder how long it'll be until a hostile fork if he doesn't change his mind.

If you can't calmly go "ah, I see why they did X, but I would prefer if they did Y," I think the problem is only on your end. Let's be adults/engineers. I've found that if all you can say is "I hate this", you usually don't actually understand the trade-offs. In the meantime, you have Sorbet available. What's the problem?

Adults and engineers both hate things sometimes (tone policing, for example).

Both sorbet and RBS have put huge amounts of effort into bolting type systems onto ruby in ways that don't run afoul of Matz's categorical and in-principle rejection of adding type-annotation syntax to the core language. Both or either of these projects would have much better ergonomics without having to bend to this constraint.

As ruby's user base skews further and further away from the hobbyist market and toward the startups that began in the period when ruby was 'cool' that have now grown up into enterprises, this pressure will continue. If Matz doesn't recant, the two possible futures are:

1. Deep compromise (see Sorbet, RBS) to keep types out of the core language; or

2. A hard fork, or a one-level-up language like typescript.

Re: RBS, Ruby’s new type signature language

#90
post #16

Can someone explain why the types cannot live in Ruby code itself (after an appropriate version bump)? Python 3 incorporated types into the language itself, in a similar way (though non-reified) to PHP. This seems much easier to deal with than requiring two files (.rb and .rbs) to describe a single data structure.

Based on the relative smoothness of Ruby version transitions versus Python, I trust Matz’s preference on this implicitly. One good thing about it being external is that you can optionally and experimentally annotate existing code without munging up your source files. At least so long as this is a bleeding edge feature, that separation makes a lot of sense to me. It’ll be a while before anyone can be confident in a particular model for how this should work, until it’s been in use for a good long while.
Post reply on HN