by gurgeous · 1y ago · 0 comments
Depending on a library that uses ducktyping (like any sane library following the Ruby conventions)? Good luck writing a wrapper for it. Or just disable type checking.
This goes so much against the Ruby vibe that I advise you to just go and use Rust instead if you hate Ruby that much that you want to butcher it with types.
Ruby has a strong history and tradition of TDD/unit testing. This is partially a crutch for its lack of static type analysis. Ultimately checking for bugs before running code is very useful
Python, Javascript (via Typscript), PHP, Elixir
have embraced Gradual Typing/Type Inference.You use typed variables/typed function signatures when it's convenient, they give you some compile-time contracts, easy documentation and probably even speed. Otherwise they don't exist. I don't do Ruby, but Gradual Types/Type Inference is a no-brainer for dynamic languages, practically no drawback, only benefits. (And popular statically typed languages such as C/C++, Java, Rust support Type Inference, or are going there too.)
> I don't do Ruby
So why have an opinion?
Languages I use: Ruby, C++, Odin, R. I'm not about to to around telling Rust, Python or Typescript people they're doing their languages wrong, even if there's things I hate about those languages. I just don't use them.
It seems you have a lot of opinion here without really discussing your problem with type hints though. What is it you dislike?
I use Ruby regularly, have used it for more than a decade, and I wish it had something like a TypeScript equivalent (Sorbet is sorta this but not enough). Every time I work with a Ruby codebase without Sorbet, it’s a lot of guessing and praying that test coverage is good enough. It’s not fun having to find out in prod there’s dumb bugs that would have been caught by static analysis. Something I experience virtually never in TypeScript, the other language I’ve also used for a decade
def somemethod(foo, bar)
foo => Integer
bar => MyBarClass
end
Personally I think the RBS-Inine format is the way forward. Sorbet has experimental support for it too.It does welcome nil proliferation though! Just sprinkle some `nilable` around and you're set to continue the actual scourge of the language.
There's also benefits to dynamically typed languages, namely runtime metaprogramming.
Dynamic typing + type annotations is the worst of both worlds for questionable benefit.
Agree to disagree!
If you actually want types in Ruby, you should check out Sorbet: https://sorbet.org/