Most active commenters
  • mekster(3)

←back to thread

511 points mootrichard | 18 comments | | HN request time: 1.68s | source | bottom
1. 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 #
2. 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 #
3. azinman2 ◴[] No.23990514[source]
But as I mentioned the downside of this is that any mistakes don't become evident until at runtime. While the python way has the same problem (they're not compiled languages after all), by inlining to the existing source there's less changes for divergence to happen.
replies(3): >>23990675 #>>23991579 #>>23994964 #
4. cschep ◴[] No.23990613[source]
After reading the article I'm not sure, but.. it seems reasonable to assume that you can do both. Inline and separate files. The same way TypeScript does it.

Hopefully, anyway!

replies(1): >>23991445 #
5. ativzzz ◴[] No.23990675{3}[source]
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.
replies(3): >>23990888 #>>23991368 #>>23993618 #
6. joshuamorton ◴[] No.23990888{4}[source]
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.
replies(1): >>23991136 #
7. 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 #
8. ativzzz ◴[] No.23991136{5}[source]
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.
replies(1): >>23991366 #
9. baweaver ◴[] No.23991366{6}[source]
Yeah, there was a ton of discussion on this in the Ruby bugtracker and at core meetings. Matz is very sensitive to breaking the language with Ruby 3 and the core team is doing their best to ensure an easy transition.
10. mekster ◴[] No.23991368{4}[source]
So, why would a company with different use case than average ruby users implement stuff in the core to confuse many ruby users?
11. mekster ◴[] No.23991445[source]
Sorbet's FAQ seems to say otherwise.

https://sorbet.org/docs/faq#when-ruby-3-gets-types-what-will...

> Ruby 3 has no plans to change Ruby’s syntax. To have type annotations for methods live in the same place as the method definition, the only option will be to continue using Sorbet’s method signatures.

12. CarelessExpert ◴[] No.23991482{3}[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 #
13. punnerud ◴[] No.23991579{3}[source]
You can run Python type check before runtime at the cost of start time, or better before GIT commit or push (Git Hooks)
14. untog ◴[] No.23991708{4}[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 #
15. floatboth ◴[] No.23993586{5}[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…
16. mekster ◴[] No.23993618{4}[source]
That use case is not for most of us yet the way those companies with large code base goes into the core? I guess ruby itself already has a large code base, so it seems they got aligned but they forgot to align with the rest of the world.
17. tdeck ◴[] No.23994235[source]
But that's not really TypeScript's main approach, is it? When I think of TypeScript I think of the inline colon annotations, not the external files. Those are just a bridge for legacy code.
18. Lio ◴[] No.23994964{3}[source]
Inline types are available as a feature of the Sorbet type checker.