News for hackers. Stuff that matters.
Re:Tiny JITs for a Faster FFI by kevingadd on Wednesday February 12, 2025 @06:03PM (#43030735)
There's https://sorbet.org/ but it's not clear whether it has much adoption.
Re:Tiny JITs for a Faster FFI by zem on Wednesday February 12, 2025 @06:24PM (#43030888)
I continue to think it was a big mistake not to add syntactic support for type annotations into the base language. python did this right; annotations are not enforced by the interpreter, but are accessible both by external tools as part of the AST and bytecode, and by the running program via introspection, so tools and libraries can do all sorts of interesting things with them.

having to add annotations in a separate header file is simply too high friction to get widespread adoption.

Re:Tiny JITs for a Faster FFI by Lammy on Wednesday February 12, 2025 @06:33PM (#43030950)
IMHO (and I don't expect most people to agree but please be tolerant of my opinion!) annotations are annoying busywork that clutter my code and exist just to make people feel smart for “““doing correctness”””. The only check I find useful is nil or not-nil, and any halfway-well-designed interface should make it impossible for some unexpected object type to end up in the wrong place anyway. For anything less than halfway-well-defined, you have bigger issues than a lack of type annotation.

edit: I am quite fond of `case ::Ractor::receive; when SomeClass then …; when SomeOtherClass then …; end` as the main pattern for my Ractors though :)

Re:Tiny JITs for a Faster FFI by zem on Wednesday February 12, 2025 @06:50PM (#43031073)
as your codebase and number of collaborators get larger, it's super useful to have the type checker be able to tell you "hey, you said your function arg could be a time or an int, but you are calling time-specific methods on it" or conversely "the function you are calling says it accepts time objects but you are passing it an int"

also once you get into jit compilation you can do some nice optimisations if you can treat a variable type as statically known rather than dynamic.

and finally, even if you're not writing python at scale it can be very nice to use the type annotations to document your function parameters.

Re:Tiny JITs for a Faster FFI by Lammy on Wednesday February 12, 2025 @06:52PM (#43031098)
> also once you get into jit compilation you can do some nice optimisations if you can treat a variable type as statically known rather than dynamic.

This is something I hadn't considered. Thanks for mentioning it :)

Re:Tiny JITs for a Faster FFI by FooBarWidget on Wednesday February 12, 2025 @10:16PM (#43032303)
Sorbet is the most mature option. RBS barely has any tooling, while Sorbet works well.

It definitely isn't at the level of Typescript adoption, even relatively speaking. And it's more clunky than Typescript. But it works well enough to be valuable.

Re:Tiny JITs for a Faster FFI by Lio on Thursday February 13, 2025 @03:36AM (#43033964)
It's interesting that RBS support is used by IRB for type completion.

There is also work to settle on an inline form of RBS so I could see it taking over from Sorbet annotations in the future.