T-Ruby is Ruby with syntax for types

type-ruby.github.io

140 points by thunderbong 16 hours ago


kace91 - 11 hours 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?

rauli_ - 3 hours ago

I remember a time in early 2000s when everybody seemed to be raving about duck typed languages and how awesome they are. Now we have separate tools for the same languages to implement typing.

troad - 41 minutes ago

This is very cool! I like this a lot. Thank you to the poster for sharing this.

Dynamic languages have amazing dev speed, but once code matures, slapping some types on that code is just plucking low hanging fruit. It inevitably picks up easy bugs and makes the code easier to read, understand, and maintain.

Ruby has had no good solution to dynamic typing, for reasons well articulated by the linked piece. Honestly, that kept me from writing much Ruby recently. Every line just felt like instant tech debt, short of any sensible pathway to static analysis.

This might just get me writing some Ruby again.

viraptor - 33 minutes ago

I love the idea, even if the implementation is basically a workaround for upstream resistance. Since it's Ruby and the goal is to be concise and pretty, I hope they will spend some extra time on inferring basic things. In the example, the function is obviously returning a string, so dropping that explicit annotation would be great.

t-writescode - 9 hours ago

That article was way better prepared than I was prepared for. I like how it translates its code into Ruby's official types-in-headers format. Very nice.

I think this is a nice way to include types into a project if you like it. I know when you're working on large Ruby projects - 10s of thousands of lines across hundreds of files - types become really, really helpful to figure out what on earth is happening where. In the past I've used DryRb and was pretty happy with it; but an even deeper connection, like this, looks wonderful.

I'd really enjoy it, I think :)

Alifatisk - 2 hours ago

We are seeing multiple attempts to Ruby with types now, previously we only had Sorbet and Rbs (with rbs-inline), but now there is also Low_type and T-Ruby. I am curious about this direction, this shows the language is still growing, changing and adapting.

I've seen some mention Crystal as well, but as far as I know, Crystal has nothing to do with Ruby except sharing similar syntax. Their semantics are completely different. It's not Ruby + types.

Levitating - 3 hours ago

Ugh more transpilers.

I think low_type is a much more elegant solution: https://github.com/low-rb/low_type

gls2ro - 7 hours ago

> Requires learning sig block's unique DSL syntax.

This is an interesting proposal. But for posterity I am going to critique the critique on the website about Sorbet:

Sorbet is Ruby and while it has a DSL that is no different than any other gem providing methods or objects to use. For example you can define a type and assign it to a Ruby constant. Because Sorbet is Ruby.

In general I would say any type system has its own syntax when you go deep into it and need more than this param has this simple primitive type and the method returns this simple primitive type. So you have to learn a DSL and the syntax of a type system.

omarqureshi - 9 hours ago

I don't programme much any more but the whole beauty of Ruby that it pretty much heavily relies on #respond_to? / duck typing and thus you don't rely on types or class checking at all.

jstummbillig - an hour ago

Does anyone have any actual insight into why optional typing is not a native Ruby feature?

exabrial - 8 hours ago

Worth mentioning is Crystal lang: Ruby, with types!

rajangdavis - 10 hours 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!

jhealy - 10 hours 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

satyanash - 6 hours ago

On Firefox, newlines in code blocks are broken for this website. This causes the page to scroll horizontally to accommodate all the code blocks. The code is all wrapped in a single line.

omoikane - 9 hours ago

> https://type-ruby.github.io/playground

The playground seems broken, I can't get it to report any kind of error. It seems to accept even syntactically incorrect files (e.g. just one unmatched closing parenthesis).

wsc981 - 11 hours 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.

zingar - 5 hours ago

I don’t like types in separate files but I also don’t want them cluttering my signatures. Types in comments would be my ideal, am I the only one who prefers this?

Edit: I see sorbet supports this as an experimental feature https://sorbet.org/docs/rbs-support

shevy-java - 10 hours 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.

rubyfan - 8 hours ago

looks a lot like Crystal

bataowt - 9 hours ago

As someone who has been raising the concern of lack of type hinting in Python and Ruby since the beginning, this is a welcoming change with a “meh” on top. Also the whole shitshow with Go and generics that never made any sense.

Oh well.

jrochkind1 - 10 hours ago

Wait, what happens if you want keyword arguments?

burnt-resistor - 9 hours ago

Yes. The proper way of adding gradual typing like Python, Typescript, and other platforms have. steep doesn't work in the rbs camp and sorbet in the rbi camp is more powerful with static and dynamic analysis, but it's also painful. The half-measures hand-wringing of separate type files, type, checking fragmentation that isn't usable, and awkward magic boilerplate comments are signs of leadership failure. Matz ain't software Jesus, sorry.

fatih-erikli-cg - 7 hours ago

[dead]

koteelok - 10 hours ago

Don't show this to DHH