Most active commenters
  • dismalaf(5)
  • jameslk(3)

←back to thread

333 points steveklabnik | 23 comments | | HN request time: 0.001s | source | bottom
1. gurgeous ◴[] No.45035053[source]
I am so excited about this!! Ruby tooling is already pretty good, but we can do better. I will try to contribute. Now we just need types
replies(2): >>45035149 #>>45040884 #
2. dismalaf ◴[] No.45035149[source]
Please no types... They're worse than pointless for a dynamically typed language.
replies(5): >>45035235 #>>45035294 #>>45035575 #>>45035612 #>>45040464 #
3. GrantMoyer ◴[] No.45035235[source]
Pyright catches an awful lot of dumb mistakes I make in Python.
replies(1): >>45035739 #
4. jameslk ◴[] No.45035294[source]
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
replies(1): >>45036528 #
5. pxc ◴[] No.45035575[source]
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.
replies(2): >>45036553 #>>45037384 #
6. seabrookmx ◴[] No.45035612[source]
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.
replies(1): >>45039925 #
7. notpushkin ◴[] No.45035739{3}[source]
Sidenote, but you might also want to give basedpyright a try (basically FOSS Pylance reimplementation): https://docs.basedpyright.com/
8. phoronixrly ◴[] No.45036528{3}[source]
My beautiful experience with sorbet: Yeah, ducktyping? We don't do that here.

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.

replies(1): >>45041025 #
9. phoronixrly ◴[] No.45036553{3}[source]
Oh exactly what I wanted - runtime overhead, on top of its lack of ability to accomodate ducktyped external dependencies in any sane way.

It does welcome nil proliferation though! Just sprinkle some `nilable` around and you're set to continue the actual scourge of the language.

10. Lio ◴[] No.45037384{3}[source]
I'm definitely in favour of gradual typing but runtime checking is already really easy to do if that's what you want. Just add a rightward assignment patten match to your method. e.g.

  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.

https://sorbet.org/docs/rbs-support

11. dismalaf ◴[] No.45039925{3}[source]
I use statically typed languages. There's benefits.

There's also benefits to dynamically typed languages, namely runtime metaprogramming.

Dynamic typing + type annotations is the worst of both worlds for questionable benefit.

replies(1): >>45084608 #
12. bmacho ◴[] No.45040464[source]
All dynamically typed Ruby competitors like

  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.)

replies(1): >>45040797 #
13. dismalaf ◴[] No.45040797{3}[source]
Cool. People who want gradual typing can use those and leave Ruby alone.

> 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.

replies(1): >>45041283 #
14. bingo-bongo ◴[] No.45040884[source]
Take a look at Crystal for types: https://crystal-lang.org/
replies(1): >>45041689 #
15. jameslk ◴[] No.45041025{4}[source]
Sorbet has its flaws. I didn’t like it either. Having used TypeScript extensively, there is a way to do it right and a way to do it wrong. I’d classify TypeScript as the ideal way to introduce static types into a very dynamic language, given its extensive flexibility to handle dynamic features in a language (e.g. smart type inference, ‘is’ keyword, very flexible generics). Sorbet doesn’t have a lot of those features

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

16. jameslk ◴[] No.45041283{4}[source]
Ruby already has this with Sorbet. Nobody is forcing you to use it, are they?

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

replies(2): >>45041430 #>>45042203 #
17. dismalaf ◴[] No.45041430{5}[source]
> It seems you have a lot of opinion here without really discussing your problem with type hints. What is it you dislike?

It's runtime overhead (or you make a transpiler which then makes the language less dynamic), makes metaprogramming more annoying (other languages solve this with an "any" type which just defeats the purpose), and the "problem" it solves can be solved with tests which you should be writing anyway.

I do use statically typed languages BTW, I just prefer that if I'm going to go through the rigmarole of types that I'm going to get some actual benefit, namely an order of magnitude more performance.

My opinion is probably this since I don't work for a large corporation, I have my own startup, so I value my time a lot. I'm ok with trade-offs, I just think adding type hints to a dynamic language isn't a good trade off; it's almost all downside.

Edit:

> guessing and praying that test coverage is good enough.

You can always improve your test coverage...

replies(1): >>45042231 #
18. dcchambers ◴[] No.45041689[source]
Crystal is cool but the only thing it shares in common with Ruby is a similar syntax.

If you actually want types in Ruby, you should check out Sorbet: https://sorbet.org/

19. tracker1 ◴[] No.45042203{5}[source]
Even after over a decade with TypeScript, I'm still kind of mixed on it... there are a lot of times where trying to wrangle typing is more painful than it should need to be... I'll often just cast to any, then I have to add a comment to suppress the error message with the default config. I use deno a lot and tend not to mess with the default configuration there. Even with node/npm, I still don't do much with the tsconfig beyond what a minimal need is.

It's not as painful as earlier versions and is generally okay to work with... but there are definitely times you need to work around the typing as opposed to with it. For example extending/using context in hono/oak/koa so you get hinting, but want your endpoint handlers in separate modules. It gets very messy, very quickly.

20. tracker1 ◴[] No.45042231{6}[source]
For me, at least with TypeScript the single biggest advantage is the hinting you get from 3rd party packages/modules. This goes for building modules as well, you can use jsdoc directly, but it's even more cumbersome than TS imo.
replies(1): >>45042411 #
21. dismalaf ◴[] No.45042411{7}[source]
It's kind of annoying that static type introspection has become the norm for language servers because live environments are so much better. With Ruby you have the REPL and there have been IDEs and tools that allow runtime reflection which is just so much better (think Lisp or Smalltalk). LSPs are nice for static languages but compared to live environments they're a step down...
22. seabrookmx ◴[] No.45084608{4}[source]
> the worst of both worlds

Agree to disagree!

replies(1): >>45116979 #
23. ◴[] No.45116979{5}[source]