T-Ruby is Ruby with syntax for types

(type-ruby.github.io)

53 points | by thunderbong 6 hours ago

7 comments

  • kace91 1 hour ago
    Honest question:

    I like typescript and I think it makes sense:, the web makes you married to JavaScript, so it’s the reasonable path forward if you want types in that context.

    But what is the point of the recent wave of types for python, Ruby, and similar languages?

    If it’s type safety you want there, there’s a bajillion other languages you can use right?

    • zem 9 minutes ago
      the overall field is known as "gradual typing", and it is an attempt to combine some of the benefits of both static and dynamic typing (or to put it more accurately, to explore more of the benefits and tradeoffs on the static to dynamic spectrum). in the "type checkers for ruby/python/js" part of the spectrum what you are trying to ask is "how much static type safety can I add without giving up the power of the dynamic bits", so for instance you have code that generates classes as runtime (not really compatible with a strictly static type system in the most general case), but specific very common uses of code generation, like python's dataclasses, have support within the type checker.
      • shevy-java 5 minutes ago
        That still has not really explained why they (those who propose that) need types in ruby specifically. Whether python has it or not is not relevant because it is another language. The argument that "language xyz has it, so ruby needs it", can be compelling, but does not necessarily have to be compelling. It needs to have a use case for ruby in and by itself. I don't see that intrinsic use case.
    • shevy-java 6 minutes ago
      Yeah. I have the same question and none of the type addicted folks could answer that. The explanations usually boil down to "I used C, so now I need types in other languages too". That's like 90% of the explanations you can see.
    • MGriisser 52 minutes ago
      (I'm not sure if this still holds under a world where LLMs are doing the majority of writing code but this is my opinion from prior to LLMs)

      From someone who has worked mostly in Ruby (but also Perl and TypeScript and Elixir) I think for web development, a dynamic language with optional types actually hits maybe the best point for developer productivity IMO.

      Without any types in a dynamic language, you often end up with code that can be quite difficult to understand what kinds of objects are represented by a given variable. Especially in older poorly factored codebases where there are often many variations of classes with similar names and often closely related functions it can feel almost impossible until you're really familiar with the codebase.

      With an actual fully typed language you're much more constrained in terms of what idioms you can use and how you can express and handle code by the type system. If you're not adept or knowledgeable about these things you can spend a lot of time trying to jam what you're attempting into the type system only to eventually realize it's impossible to do.

      A gradual type system on top of a dynamic language gets you some of the best of both worlds. A huge amount of the value is just getting typing at function boundaries (what are the types of the arguments for this function? what is the type of what it's returning?) but at the same time it's extremely easy to just sidestep the type system if it can't express what you want or is too cumbersome.

    • matteotom 1 hour ago
      At least for Python (since I'm more familiar with Python code and the Python ecosystem): progressive typing lets you incrementally add typing to an existing Python codebase. So you can have at least some of the benefits of typing for new or updated code without needing to re-write in a new language.
    • rajangdavis 44 minutes ago
      I have been programming with Ruby for 11 years with most of the time in a professional context. It's my favorite language :).

      I don't care much for types, but it can be useful with denser libraries where IDE's can assist with writing code. It has been helpful in my professional life with regards to typed Python and Typescript.

      One potential example that would be interesting is utilizing types for reflection for AI tool calling, the python library for Ollama already supports this[0].

      It would make it easier to use such tools in a Ruby context and potentially enhance libraries like ruby-llm [1] and ollama-ruby [2].

      [0] https://docs.ollama.com/capabilities/tool-calling#using-func...

      [1] https://rubyllm.com/

      [2] https://github.com/flori/ollama-ruby

    • lofaszvanitt 7 minutes ago
      Religious coders spreading their religion.
    • wawj 1 hour ago
      Languages take time to get used to and to get productive in. IF you already know Ruby, and want the same safety as C# for instance, then this makes sense.
  • shevy-java 8 minutes ago

        def greet(name: String): String
          "Hello, #{name}!"
        end
    
    Yep - looks like utter s...

    I understand that many programmers come from languages where their brain has been adjusted to necessitate and depend on types. And they get help from the compiler in capturing some errors. But it is the wrong way to think about programs and logic. I'd wish these guys would stop trying to ruin existing languages. Go add types somewhere else please.

    Note: I also use java, so I am not against types per se. I am against a want-on need to slap down types onto everything and your Grandma, merely because your brain (of type afficionados) needs them for survival.

  • rajangdavis 52 minutes ago
    If it is at all possible, it would be nice to have a little bit better support for metaprogramming namely around `define_method` and supplying a typed lambda or block for the dynamic method. I can see why this would be a pain to implement, so I don't expect it :).

    Otherwise, I think in terms of typed Ruby, this is an incredible undertaking with very well written documentation. Thank you for making this library, I think there's a lot that the Ruby community can benefit from with it. Cheers!

  • koteelok 2 minutes ago
    Don't show this to DHH
  • wsc981 1 hour ago
    In the context of Lua, I’ve taken a liking to LuaLS (Lua Language Server). You can just write your Lua scripts with annotations (where needed) and the language server can help auto-complete and verify type usage. No compilation step needed.

    I never tried “typed Lua” variants (such as MoonScript IIRC), but I believe those do require a compilation step.

  • jhealy 27 minutes ago
    interesting idea, good on them for trying something different in the Ruby ecosystem.

    The website is quite extensive, but the gem only has ~1.5k downloads. It’s presumably very early on the adoption curve

  • jrochkind1 44 minutes ago
    Wait, what happens if you want keyword arguments?