Looking for more aesthetically pleasing contract DSLs - suggestions?

This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.

Anyone else find Sorbet lacking aesthetic appeal?
I found https://github.com/bluebottlecoffee/CBRA-Contracts, which seems a bit nicer.
Any other contract DSLs that you’re using?

Thanks for sharing! (I can’t believe I never heard of this :smile: )

Message originally sent by slack user U70TIGAX94P

We developed our own thing inspired by dry-schema and activemodel validations at Shopify, however decided to prefer Sorbet in the end mostly because of runtime performance concerns.

The drastically shortened feedback loop enabled by static analysis was another reason.

There was a bit of pushback against sorbet (from me, amongst others) because it is very verbose (virtually no inference) and restricts the language (no duck typing), but in the end it was, and I think still is, by far the most mature static type checker for Ruby. And that in itself is worth a lot.

Message originally sent by slack user U70TIGAX94P

We also used, on a few smaller (but still large) apps, a gem that would parse yard annotations and generate runtime type checks from them. That approach too has been mostly abandoned for the same reasons mentioned above.

<@U70TIGAX94P> Do you use it only in the public interface of each package/component, or on public methods of every ruby class?

Message originally sent by slack user U70TIGAX94P

because sorbet doesn’t have type inference across methods, its utility is greatly reduced if signatures are far apart in the call stack. So you kind of need signatures on most methods. That’s my main gripe with Sorbet. I would have loved to just use type signatures for all package APIs and then sprinkled over the rest of the code where they make sense.

Message originally sent by slack user U70TIGAX94P

e.g. if a method‘s signature specifies only that a parameter is to satisfy a certain interface, methods outside of that interface can’t be called on that parameter within that method. But then if that value is passed on to a method that doesn’t have a signature, we lose that type safety and all methods can be called on it.

Message originally sent by slack user U70TIGAX94P

So, in consequence, there‘s been an effort at Shopify to add signatures everywhere.

I see

Thanks for clarifying that.