←back to thread

511 points mootrichard | 4 comments | | HN request time: 1.067s | source
Show context
azinman2 ◴[] No.23990204[source]
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.
replies(2): >>23990400 #>>23990613 #
CarelessExpert ◴[] No.23990400[source]
> 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.

replies(3): >>23990514 #>>23991134 #>>23994235 #
1. untog ◴[] No.23991134[source]
> 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.

replies(1): >>23991482 #
2. CarelessExpert ◴[] No.23991482[source]
> They didn't, though! That's what's confusing me.

Sure they did. It's the 5th paragraph in the post:

"We defined a new language called RBS for type signatures for Ruby 3. The signatures are written in .rbs files which is different from Ruby code. You can consider the .rbs files are similar to .d.ts files in TypeScript or .h files in C/C++/ObjC. The benefit of having different files is it doesn't require changing Ruby code to start type checking. You can opt-in type checking safely without changing any part of your workflow."

replies(1): >>23991708 #
3. untog ◴[] No.23991708[source]
They've described part of TypeScript's approach.

.rbs files: have types

.rb files: no types

.d.ts files: have types

.ts files: have types

It's a pretty significant difference. So they didn't "follow typescript's approach" here.

replies(1): >>23993586 #
4. floatboth ◴[] No.23993586{3}[source]
Well, .rb types won't have the standard type signatures (that could be consumed by various typecheckers) but could still have a particular typechecker's custom annotations…