Live data from Hacker News

Embed Crystal code directly in Ruby

github.com

31–40 of 65 posts

Re: Embed Crystal code directly in Ruby

#31

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…

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 to write a generic signature for that method, otherwise type checking is not working anymore. Generic signatures are even more verbose and hard to write than for methods with specific types.

So, a kneejerk reaction would be just not extract those, because it becomes too much work, and readability is not improved anymore, because signature for three lines of code is taking five lines. And that's until someone "clever" will add a rule to rubocop limiting all methods to a specific amount of lines indiscriminately, so I'd spend additional work time imagining that person being punched in a face.

In theory something like that could be solved by marking helper methods as inlined, basically promising that you're not going to use them in subclasses or whatever and allowing the same inference to work inside. But "sorbet is feature complete".

Re: Embed Crystal code directly in Ruby

#36
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

Monkeypatching was common a decade ago. Now it’s more limited to things that try to be language or framework extensions, like ActiveSupport or gems extending ActiveRecord. The whole point of those is to deeply integrate.

Metaprogramming like looping over an array to dynamic create methods is far less common. It definitely makes me cranky when I can’t find a method definition. ORMs are one of a few exceptions where the utility justifies it.

Re: Embed Crystal code directly in Ruby

#37

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?

[deleted]

Re: Embed Crystal code directly in Ruby

#38

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.

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.

Re: Embed Crystal code directly in Ruby

#39

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?

Towards the end it gives an example on how to precompile in advance
Post reply on HN