Live data from Hacker News

Switch from Ruby to Crystal

blog.logrocket.com

31–37 of 37 posts

Re: Switch from Ruby to Crystal

#31
post #7

Anyone have production experience with Crystal? I know it's not 1.0 yet, but there are some fairly mature web frameworks available that make the language look pretty attractive.

not production yet, but if you are looking to make simple apis, you can just go with the stdlib. Like golang, the Crystal http stdlib module is good enough for use in your project. Here is my half done repo where I have used it for a repo https://github.com/rishavs/noir, if you are looking for a reference.

The major things you might struggle with;

* Lack of IDE support. The DevEx is not that great compared to the other languages. * Long compilation times. Specially if you add more libs to your project. * http/2, postgres pipelining and async drivers. Not a big deal as the Crystal drivers are performant enough. * lack of community packages. Most stuff will have to be done by hand.

Re: Switch from Ruby to Crystal

#32
Mildly offtopic but this is a thread most likely to have Crystal and youtube-dl fans in it:

Invidious needs your help!

invidious[1] is an open alternative frontend to youtube with low bullshit, that works without js. It's written in Crystal. The core developer decided it was too much for them and has taken a (likely permanent) break from the project[2], and the community is struggling to maintain it[3] because there's very few people who have ever seen or heard of Crystal and like youtube-dl it's subject to breakage whenever google tweaks something on the youtube page. If you are a Crystal person and this is of interest to you, please help. For a bit more information on the way the code is structured and the current work that's happening, see [4]

[1] https://github.com/iv-org/invidious

[2] https://github.com/iv-org/invidious/issues/1320

[3] https://github.com/iv-org/invidious/issues/1411

[4] https://github.com/iv-org/invidious/pull/1399

Re: Switch from Ruby to Crystal

#33
post #3

> So, what’s the catch? No windows support. (Seems to be progressing, though) https://github.com/crystal-lang/crystal/issues/5430

The funny thing about the lack of "windows support" is that crystal is already good enough for windows programs which don't need networking (which is the only missing piece). Crystal can already work on Windows for use cases like gamedev (see crSFML), console apps, AI/ML etc.

Yet the Crystal team hasn't made a preview windows build which can enable all those use cases and the act of using Crystal on Windows is super convoluted as a result.

Re: Switch from Ruby to Crystal

#34

There are a couple of points where Crystal really feels cleaner and somehow more expressive than Ruby. The authors of the language avoided aliases (no more size vs. length or inject vs. reduce discussions) and generally there's only one way to do things (Strings are always wrapped in double quotes). Crystal has abstract classes/modules/methods, generics and method overloading, three powerful techniques which are miss…

I have written almost the identical Scheme interpreters in Ruby and Crystal: [1] and [2]. The biggest difference I have felt between them is the absence of good old Object, which can represent everything at runtime, from Crystal. I had to declare Obj and Val:

  class Obj
  end

  # Value operated by Scheme
  alias Val = Nil | Obj | Bool | String | Int32 | Float64 | BigInt
to define Cons Cell of Scheme:

  # Cons cell
  class Cell 
Note that you see generics, Enumerable(Val), and constructor arguments with '@' in the excerpt above.

As for performance, Crystal is faster than Ruby 8.6 times as interpreter and 39.4 times as compiler [3]. You can use Crystal as a superfast (and typed) Ruby interpreter, in a sense.

[1] https://github.com/nukata/little-scheme-in-ruby [2] https://github.com/nukata/little-scheme-in-crystal [3] https://github.com/nukata/little-scheme#performance

Re: Switch from Ruby to Crystal

#35

I have a love-hate relation with Crystal. Every few months, disenchanted with the core maintainers' priorities, lack of platform and tooling updates and overall deadland syndromes - I denounce Crystal, promise I will never use it again, startup a golang or Rust project, make some non trivial toy stuff and then come crawling back to Crystal. I hate the fact that I love this language and the fact that nothing else (exc…

Go is simple. I can't, however, say I find go remotely as productive as I find ruby. In fact, literally nothing I've found is as productive as ruby. I've had high hopes that crystal would become a better, faster, more capable ruby, but I share your concerns.

I left ruby and rails years ago, and here I am in 2020 thinking about going back. I've made very strong attempts to use python, go, kotlin and groovy in the years since, but literally nothing touches ruby in terms of sheer developer productivity (at least for me...ymmv). I suppose I'll look at elixir next...

Re: Switch from Ruby to Crystal

#36
The networking side of things still isn't mature.

A couple of years ago, I tried to write a parallel download app as my first Crystal app. It ended up as slow as the Ruby version. After some digging, I found out it was because the DNS resolver wasn't multithreaded.

Years later, the issue is still open.

https://github.com/crystal-lang/crystal/pull/2829

https://github.com/crystal-lang/crystal/pull/4236

It's still a good fit for CPU-bound workloads, and efficient background jobs and where I wouldn't want to install Ruby. Also seems be a good fit for AWS Lambda.

Re: Switch from Ruby to Crystal

#37
post #19

Earlier quoted context omitted.

Crystal has macros which is the metaprogramming for static/compiled languages. And last time I checked, there are way more things that you can do with Crystal macros than Rust's macros. And crystal's macros feel very familiar to the language itself, are easy to understand and use them whereas Rust's macros..

According to [1], Crystal Macros "receive AST nodes at compile-time and produce code that is pasted into a program." This is basically the same as Rust procedural macros[2]. You're probably thinking of "Macros by example"[3] [1] https://crystal-lang.org/reference/syntax_and_semantics/macr... [2] https://doc.rust-lang.org/reference/procedural-macros.html [3] https://doc.rust-lang.org/reference/macros-by-example.html

Being able to receive AST in crystal is only good. However have a look here [1], 90% of your macros are covered with those helpers. In Rust doing the same things are either more difficult or impossible. For instance, I wanted in rust to inject allow/warn kind of derives based in env var. Nope.

[1] https://crystal-lang.org/reference/syntax_and_semantics/macr...

Post reply on HN