Static analysis through type hints brings plenty of benefits to a dynamic language, such as helping to eliminate bugs at runtime (albeit not perfectly) and making it easier to grok a codebase. It’s a trade off and Ruby is as dynamic as it gets. But there is a point to it
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.)
Sorbet can actually make programs crash at runtime if a variable's type doesn't match its annotation, right? It's not as busted as some other gradual typing implementations.
Many smart engineers (including Guido) disagree with you, and have added static types to Python, Javascript, Dart, Elixir, Hack and surely some I'm forgetting.
dismalaf|6 months ago
jameslk|6 months ago
GrantMoyer|6 months ago
bmacho|6 months ago
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.)
pxc|6 months ago
seabrookmx|6 months ago
bingo-bongo|6 months ago
dcchambers|6 months ago
If you actually want types in Ruby, you should check out Sorbet: https://sorbet.org/