Live data from Hacker News

Embed Crystal code directly in Ruby

github.com

11–20 of 65 posts

Re: Embed Crystal code directly in Ruby

#11

What is the current state of crystal toolchain? Last time I used it I really enjoyed the language but the compilation times were a bit of a turn off.

You won't ever see fast compilation times with it, and here's why:

> type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1]

I prefer Sorbet[2] for Ruby, which is pretty fast and a reasonable compromise. People complain about the verbosity, but you can't have both speed and type inference. Pick one.

Some of the verbosity in Sorbet, however, comes as an indirect result of an underdeveloped Generic type system (the rest of the parts work great though). Some of the verbosity comes from lack of fluency with the tool, which gets better with practice, and doing research. The bottom line is I often think its a skill issue when people say it leads to code that is too verbose.

1. https://crystal-lang.org/#type_system 2. https://sorbet.org/

Re: Embed Crystal code directly in Ruby

#12
post #9

Earlier quoted context omitted.

It would definitely be possible, but I would really hate to see coupling like that added to ruby. I also worry that it would make it too magical and difficult to figure out what code is running, where and when. Debugging an issue deep in the bowels of that is a scary thought.

> to ruby. I also worry that it would make it too magical and difficult to figure out what code is running, where and when Coming from both python and statically-typed languages, your description 100% squares up with every experience I've had with ruby Folks are free to throw stones at the Spring Framework similarly, it's not out of bounds, but ruby seems to embrace the monkeypatch

> ruby seems to embrace the monkeypatch

How recent were your experiences with this? In recent years I've seen monkeypatching treated as more of an antipattern. If you are on a project where people are doing that without very good reasons, that says more about the team than the language.

Re: Embed Crystal code directly in Ruby

#13

What is the current state of crystal toolchain? Last time I used it I really enjoyed the language but the compilation times were a bit of a turn off.

Mega thread that has been discussing this for a year: https://forum.crystal-lang.org/t/incremental-compilation-exp...

Re: Embed Crystal code directly in Ruby

#14
post #9

Earlier quoted context omitted.

It would definitely be possible, but I would really hate to see coupling like that added to ruby. I also worry that it would make it too magical and difficult to figure out what code is running, where and when. Debugging an issue deep in the bowels of that is a scary thought.

> to ruby. I also worry that it would make it too magical and difficult to figure out what code is running, where and when Coming from both python and statically-typed languages, your description 100% squares up with every experience I've had with ruby Folks are free to throw stones at the Spring Framework similarly, it's not out of bounds, but ruby seems to embrace the monkeypatch

I think that’s a misconception of people who don’t understand the underlying language/framework (yet).

How much magic is really going on, especially compared to for example JPA/Hiberbate, or any of the aspect orient projects?

Re: Embed Crystal code directly in Ruby

#15

What is the current state of crystal toolchain? Last time I used it I really enjoyed the language but the compilation times were a bit of a turn off.

You won't ever see fast compilation times with it, and here's why: > type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1] I prefer Sorbet[2] for Ruby, which is pretty fast and a reasonable compromise. People complain about the verbosity, but you can't have both speed and type inference. Pick one. Some of the verbosity in Sorbet, howe…

Do you have some examples of programs using generics in Sorbet you would prefer worked better or differently?

Re: Embed Crystal code directly in Ruby

#16
post #15

Earlier quoted context omitted.

You won't ever see fast compilation times with it, and here's why: > type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1] I prefer Sorbet[2] for Ruby, which is pretty fast and a reasonable compromise. People complain about the verbosity, but you can't have both speed and type inference. Pick one. Some of the verbosity in Sorbet, howe…

Do you have some examples of programs using generics in Sorbet you would prefer worked better or differently?

I'll have to dig deeper into it to put together some sorbet.run code and identify which issues are the most serious. I'll share with the community group whenever I have things worth posting.

That said, in general, I often end up rewriting things a different way if something doesn't work, and the vast majority of the time that is good enough for me. But it takes time to find the one solution that doesn't create unacceptable bloat or complexity, and even then it is not as simple as I think it could be if there was another layer of polish to the Sorbet ergonomics (don't get me wrong, it's already in a good spot considering where Ruby was before that). Though someone actually complained to my boss that I spend too much time getting things working with Sorbet instead of "just shipping it", even though one of my main areas of responsibility is with architecture.

This is where having redundant features (multiple ways to accomplish the same thing) could be of some benefit, but I'll have to think about it some more with specifics. And I understand from looking through the repository that it's not an easy task to add features at all, so I'm thankful enough for what it is there as it has made my job much easier overall.

The main thing I struggle with regarding generics is the scenario where you must have separate type_template and type_member for class methods vs instance methods, and there are many use cases where these values are equal. But there is no way to tell sorbet that they are equal, requiring casts which makes the code less readable and often frustrating to write.

I also think that on a broader level, based on my searches, that the ruby community criticizes the idea of Sorbet for the reasons I mentioned in my previous comment. Adding more polish to the ergonomics, even when difficult or seemingly unreasonable, could do more for the branding of the project, which would lead to more community adoption, which would lead to better "just-works" type support with many common ruby libraries that are currently untyped. That could be a massive improvement to the status quo IMO. But it's hard to say because it could also end up not really moving the needle...

Appreciate all the work you've done! C++ isn't my strong point but someday I hope to find time to do a deep dive on the internals of the project.

Re: Embed Crystal code directly in Ruby

#18
post #4

Wonder if it would be possible/useful to have the Ruby interpreter itself identify eligible functions and "crystalize" them automatically

Conceptually, isn’t that what a JIT compiler does?

Crystalruby ia really interesting though. This has got me wondering:

1. How this compares to Sorbet Compiler in terms of performance?

2. If you could use Sorbet or RBS type annotations to drive crystalruby?

3. How would YJIT perform if it was fed with type annotations?

4. Could crystalruby type signatures be used by Sorbet-lsp, ruby-lsp, etc in to improve developer experience?

I really wish we had a single standard for inline types in ruby. I wish that was an inline RBS type annotation but I guess I’d take anything that works.

Re: Embed Crystal code directly in Ruby

#19

What is the current state of crystal toolchain? Last time I used it I really enjoyed the language but the compilation times were a bit of a turn off.

You won't ever see fast compilation times with it, and here's why: > type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1] I prefer Sorbet[2] for Ruby, which is pretty fast and a reasonable compromise. People complain about the verbosity, but you can't have both speed and type inference. Pick one. Some of the verbosity in Sorbet, howe…

> but you can't have both speed and type inference. Pick one.

With OCaml you can pick two :)

Re: Embed Crystal code directly in Ruby

#20

What is the current state of crystal toolchain? Last time I used it I really enjoyed the language but the compilation times were a bit of a turn off.

You won't ever see fast compilation times with it, and here's why: > type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1] I prefer Sorbet[2] for Ruby, which is pretty fast and a reasonable compromise. People complain about the verbosity, but you can't have both speed and type inference. Pick one. Some of the verbosity in Sorbet, howe…

> You won't ever see fast compilation times with it, and here's why:

> > type annotations are rarely necessary, thanks to powerful type inference. This keeps the code clean and feels like a dynamic language.[1]

There are fast type inference implementations. For example, the OCaml compiler is pretty fast

No reason Crystal couldn't improve this part of compile time in future

Post reply on HN