Live data from Hacker News

T-Ruby is Ruby with syntax for types

type-ruby.github.io

101–110 of 155 posts

Re: T-Ruby is Ruby with syntax for types

#101

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?

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 to…

DSPy.Rb uses static Sorbet types if that's what you're looking for.

https://github.com/vicentereig/dspy.rb

Re: T-Ruby is Ruby with syntax for types

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

Re: T-Ruby is Ruby with syntax for types

#103
post #49

Worth mentioning is Crystal lang: Ruby, with types!

How alike actually are Ruby and Crystal? I’ve heard the similarity is only skin-deep: similar syntax but quite different semantics. In other words, isn’t describing Crystal as “Ruby with types” similar to describing C++ as “JavaScript with types”?

Well they're similar enough for this project to work:

https://github.com/wouterken/crystalruby

It allows you to call crystallize on a ruby method and then have it recompile with crystal and called over FFI, which is pretty neat.

It would be really cool if this trb syntax could get close to the crystal syntax for method signatures at least.

I'd love to be able to move chucks of hot code to Crystal but leave everything else in ruby for compatibility with existing projects.

Re: T-Ruby is Ruby with syntax for types

#104
post #95

Earlier quoted context omitted.

Gradual typing is the worse of both worlds. You get the complexity and slower development times of using statically typed languages along with the bad performance of using dynamically typed languages.

Is this based on your experience or is it just an assumption? I only have anecdotes, but it does not reflect your claims, rather the exact opposite. A lot of the boilerplate code doesn’t need to be type annotated, but annotating the main business logic doesn’t take more time and is not more complicated, but instead type annotations help write code that is more clear, more obvious, and it adds some kind of documentati…

It really depends on how you tackle gradual typing on a project level. The easiest way to sabotage is a "any new code must be fukly type checked" requirement, because it often means you also need to add type hints to any code you call, which leads to Optional[Union[Any]] nonsense if you let juniors (or coding assistants) go wild.

As always, no fancy new tech is a substitute for competent project management.

Re: T-Ruby is Ruby with syntax for types

#105
post #81

Wait, what happens if you want keyword arguments?

Their docs say that something like: `def greet(name: String, greeting: String = "Hello"): String` will work for kwargs with default values — https://type-ruby.github.io/docs/getting-started/understandi...

I think they've missed a trick there, they could have used `|` like low-type does.

e.g.

  def greet(name: String | "Hello"): String
I know it's all subjective but I think that reads better and it's valid ruby.

To be honest low-type with a static analysis tool would be my favourite syntax for this.

https://github.com/low-rb/low_type

Re: T-Ruby is Ruby with syntax for types

#107

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 e…

[deleted]

Re: T-Ruby is Ruby with syntax for types

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

Re: T-Ruby is Ruby with syntax for types

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

Re: T-Ruby is Ruby with syntax for types

#110
post #81

Wait, what happens if you want keyword arguments?

Their docs say that something like: `def greet(name: String, greeting: String = "Hello"): String` will work for kwargs with default values — https://type-ruby.github.io/docs/getting-started/understandi...

That example is for positional args with default values, according to the example usage: `greet("Alice")`. Can't find ruby-style keyword args example, with or without default values. maybe no kw args in t-ruby?

Or wait, found examples that claims to be keyword arguments, but you define them just the same? I'm confused. https://type-ruby.github.io/docs/learn/functions/optional-re...

Post reply on HN