Live data from Hacker News

Embed Crystal code directly in Ruby

github.com

51–60 of 65 posts

Re: Embed Crystal code directly in Ruby

#51
post #44

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

Install the Rubocop extension in your editor and it'll bug you about it every time you have a big int (kind of annoying when you're doing one-off scripts and embed "magic numbers" like IDs from the database lol)

Re: Embed Crystal code directly in Ruby

#52

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…

what annoys me to no end with sorbet is that it subtly pushes to worse looking code, even if to ignore all the verbosity and annotations. let's say there's a generic data transformation in a method which could be extracted to a private helper method. Sorbet didn't have any issue figuring types of the result while those lines were in the parent method. But when those three lines are extracted, sorbet now requires you…

Sorbet is not feature complete, we are working on it every day!

I hear you on the verbosity of generic type declarations. It's something that I pushed hard for us to improve in the early phases of the project, but I was outvoted by other members of my team. But... at this point those members have all left the team and in the meantime we've heart actual users complain about the verbosity (not our own hypothetical "what if" complaints in the design phase) so I'm optimistic we'll be able to reduce generic type verbosity in the future. For example, a while back I did a prototype/experiment to drastically drop the verbosity of generic type annotations[1]. It's definitely on our radar.

Happy to chat more either on Sorbet's issue tracker or Slack group.

[1] https://github.com/sorbet/sorbet/pull/7322

Re: Embed Crystal code directly in Ruby

#53

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…

[deleted]

Re: Embed Crystal code directly in Ruby

#54
Awesome! I’ve been waiting to see if someone would eventually do this. With further refinement this could be a big deal for Ruby. No more “Ruby is too slow”, when you can Crystalize your bottlenecks.

One feature it seems to lack is the ability to crystalize instance methods?

Re: Embed Crystal code directly in Ruby

#55
post #44

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

Install the Rubocop extension in your editor and it'll bug you about it every time you have a big int (kind of annoying when you're doing one-off scripts and embed "magic numbers" like IDs from the database lol)

Listing cops with:

  rubocop --show-cops
I can see that the NumericLiterals cop that's bothering you supports autocorrect so running:

  rubocop -A 
should fix the problem for you.

Re: Embed Crystal code directly in Ruby

#56
post #52

Earlier quoted context omitted.

what annoys me to no end with sorbet is that it subtly pushes to worse looking code, even if to ignore all the verbosity and annotations. let's say there's a generic data transformation in a method which could be extracted to a private helper method. Sorbet didn't have any issue figuring types of the result while those lines were in the parent method. But when those three lines are extracted, sorbet now requires you…

Sorbet is not feature complete, we are working on it every day! I hear you on the verbosity of generic type declarations. It's something that I pushed hard for us to improve in the early phases of the project, but I was outvoted by other members of my team. But... at this point those members have all left the team and in the meantime we've heart actual users complain about the verbosity (not our own hypothetical "wha…

That's actually reassuring to hear, thank you. I'll take a look on recent changes in sorbet, I don't even remember where I've seen that "feature complete" remark, maybe I'm just imagined it.

I'd love and use sorbet if it'd be truly an optional typing, I'd happily supply signatures to public interfaces of my classes, but only to them, as a documentation and a somewhat verifiable helper to LSP. Basically, what RBS should be doing. In my experience I rarely if ever make type-like errors in the code I produce, so sorbet just added a lot of chore and forced to dumb down my code significantly, just to be ingestable by sorbet. And worse of all, it added some false sense of security, because absense of sorbet errors didn't mean absense of type mismatches in many cases. But maybe some of those concerns are gone already.

Re: Embed Crystal code directly in Ruby

#57
post #38

Earlier quoted context omitted.

Why does compile times matter? 4 minutes? 4 seconds? Who cares?

I have to assume you're trolling, but if not, the reason compile times matter is because iteration time is important. Having to wait longer to see the results of one's work results in loss of focus and productivity.

Yeah I know what time is. My point is, this is 2024 and computers are insanely powerful now. Compilation times can't be that bad.

Re: Embed Crystal code directly in Ruby

#59

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.

Tried crystal several times over the years. Each time, I encountered Crystal bugs, surprises, oddities, and missing pieces such that there was no viable path forward to adopt it for anything serious. Elixir + Rust with rustler is pretty compelling as a scalable, viable alternative.

Re: Embed Crystal code directly in Ruby

#60

Earlier quoted context omitted.

> but you can't have both speed and type inference. Pick one. With OCaml you can pick two :)

But then Id have to use Ocaml. ;)

Well, there's Idris which is eager fp like OCaml but looks like Haskell and has dependent typing.
Post reply on HN