I came across this link
https://developer.squareup.com/blog/the-state-of-ruby-3-typing/ and it
worried me a lot, I saw what people said on twitter and I was not alone.
Looks like most people do not like to add typing in Ruby.
Why would you be worried about an optional feature that has the support of
the language author and overseers?
Yes I do realize the benefits we might get like faster programs and so on
I'm not sure faster programs is a design goal here, as far as I'm aware the
proposal doesn't really address runtime performance at all, your variables
will still be backed by R_VALUEs under the hood, and all the runtime
reflection in the VM will still have to be done to figure out of an
"object" is a string, hash, int or other when called.
I strongly feel Ruby should be a language for humans and not language for
corporate's. It's big companies that want these typing.
I work for a company with ~20 Ruby developers, we are desperate for the
type system. We're a Rails app with some peripheral things (REST APIs,
GraphQL, that aren't strictly Rails) and most of our methods take hashes as
arguments and return hashes of hashes. This is pretty typical Ruby in my
decade of experience. We have little-to-no way of knowing what is
*necessary* in any of those hashes.
Being that we have ActiveSupport, we could pass strict instances of
ActionController::Params around, a kind of type-system that ActiveSupport
embedded into Rails for dealing with the problems of receiving untyped,
mixed-content payloads from HTTP requests. The need for a type system is
there, and it's been a core part of Rails for half a decade.
We also make extensive use of things like `dry-types`
<https://dry-rb.org/gems/dry-schema/1.5/> and things such as Re:Form and
form-objects, all of which do type structure verification and guard against
unwanted "types" (although, in the end we get hashes of hashes) into the
boundaries of the system.
Without language-level support, we're constantly reinventing variations on
"types" across the various layers in the stack, we have lots of controller
tests for our REST APIs using JSON schema to validate the "type" structure
of JSON headed out to API clients.
Are we the big corporates you're referring to when you suggest that people
are turning Ruby into a language for machines? We certainly feel like a
small shop operating in a real world of daily problems not knowing the
shape of the data going over our system boundaries.
At the same time it will be great if Ruby can learn to add types
automatically. Lets say I have a function add(a, b), on running it lot of
times, Ruby can infer that most of the time a and b are Number, and hence
it can keep a meta data of this thing it learned in a file in the same
You touched on two things here, the first thing is absolutely planned. The
design of RBS being separate in separate files is great, it means that Gem
authors can ship those support files in their gems, and people on older
Rubies before 3.0 can continue to use things without needing to support
this new magic syntax. Surely tools will be written, or have been written
already to do a type inferrence and generate types. The TypeScript
community design for this problem is almost exactly the same, and has
worked really, really well. They have CI/CD in a meta project which fetches
the untyped libraries from the most popular node projects and generates
types, and provides them via separate packages.
This way we can have faster Ruby with less programmer frustration. May be
we can use test file that tests these programs (during TDD) to add types.
Most of my frustration from Ruby comes from _not_ knowing the shape of my
incoming and outgoing data. I look forward to having a declaration file
that describes the interface unambiguously, and making sure I can write
fewer tests, and still improve the quality of my code.
I hope my position can change your opinion a bit, types are going to be
_Great_. The RBS proposal does, after all, retain the duck-typing
properties of Ruby via "interfaces". So far as I can see, there's literally
no down-side to the RBS proposal.
Please excuse the wall of text, the type system is the feature of Ruby I am
most excited about since learning Ruby in 2008.