Live data from Hacker News

Embed Crystal code directly in Ruby

github.com

41–50 of 65 posts

Re: Embed Crystal code directly in Ruby

#42
post #30
post #6

Everything old is new again… https://github.com/seattlerb/rubyinline (2002)

I don’t think the author is claiming that code interop is new. But this does seem to be the first attempt at interop between crystal and Ruby, which is notable because crystal is effectively a typesafe Ruby.

There does exist anyolite

https://github.com/Anyolite/anyolite

Re: Embed Crystal code directly in Ruby

#43

I read that during the first run, it will be slower because of the crystal code being compiled. Is the compiled code stored somewhere? I am asking this because in that case, can’t I run it myself and share the code with the precompiled parts so others don’t have to experience the slow start?

Yes that appears to be the case. If you run the single file example in the README it will add a directory called "crystalruby" with generated source code in it.

So it looks like you could easily check that in with your gem.

I don't actually see any object code in the directory but this is a new project so they may not cache that yet but I don't see why they couldn't in future. e.g. as a build step when installing a gem.

This seems to be a fantastic bit of work so far with a lot of potential for the future.

Re: Embed Crystal code directly in Ruby

#46
post #44

Ha. TIL you can do 1_000_000.times do ... (equivalent to 1000000.times do ...). That's really nice.

A lot of languages have added support for this over the last few years. It's a nice little quality of life improvement. I use it very regularly now. I find it really handy for currency amounts in cents, so I can say `10_00` for ten dollars, in cents.

Re: Embed Crystal code directly in Ruby

#48
So ruby fans want Crystal to get more publicity and python fans want Nim to get more.

Has anyone used both in any serious project, and if so can you compare? I've spent a tiny amount of time with Nim but found documentation, training videos, books etc extremely thin on the ground. Lots of Nim projects on github are ancient and haven't been updated in years. Chat GPT never gave me working code. How is Crystal in this regard? How would you compare their std libraries and available modules?

Re: Embed Crystal code directly in Ruby

#49
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?

[deleted]

Re: Embed Crystal code directly in Ruby

#50
post #15

Earlier quoted context omitted.

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

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

Makes sense, this is a big one for us too. For example, we'd like to do a better job of typing the T::Enum `serialize` and `deserialize` methods, but that's blocked on having a better mechanism for type_members that are equivalent to type_templates. I have done some prototypes to build this feature (you can find them in my draft PRs) but none of the solutions I arrived at were particularly satisfying. It's on our list to fix for sure.

> Adding more polish to the ergonomics [...] would lead to better "just-works" type support

People mean a lot of different things by this—I'd love to hear more about what kinds of ergonomic improvements would help. For example, some people say ergonomics to mean only tooling improvements, while others mean something else (e.g. type system improvements).

Post reply on HN