←back to thread

511 points mootrichard | 1 comments | | HN request time: 0.001s | source
Show context
setpatchaddress ◴[] No.23990944[source]
I'm really puzzled by the decision to use a separate file for this. The stated justification ("it doesn't require changing Ruby code") doesn't make sense, and my personal experience with languages with external type specifications is strongly negative. It's an unbelievable pain to keep multiple interface files in sync over time.

`.h` files are not something to emulate! External interfaces should be generated by tools where needed.

replies(5): >>23991001 #>>23991013 #>>23991258 #>>23991289 #>>23994203 #
heavenlyblue ◴[] No.23991013[source]
How do you even type local variables?
replies(2): >>23991291 #>>23991344 #
1. rattray ◴[] No.23991344[source]
I mentioned elsewhere that Sorbet (an implementation) allows inline type definitions. Its syntax for local variables is this:

    def foo
      username = T.let("heavenlyblue", String)
    end
It's a little clunky but gets the job done, and in practice it's quite rare that you need to type a local variable.

However, more important to have in the body of a program is tools for casting and asserting types, like these:

    T.assert_type(foo, String)
    T.cast(foo, String)
    T.must(foo) # assures the compiler foo is not nil
    T.unsafe(foo) # the equivalent of a TS `any` cast
Docs at https://sorbet.org/docs/type-assertions

I'm not sure how tools that use RBS without inline syntax will handle these situations, but to be honest I expect the community to adopt Sorbet in practice anyway. It's very fast and battle-hardened in production at Stripe and several other large companies.

Disclaimer, again: former Stripe employee.