https://crystal-lang.org/reference/1.11/index.html
I couldn't quite determine the reason of being of the Crystal language. Could someone with experience with the language explain what is its appeal, and why it would be worth trying/learning?
Thanks!
https://crystal-lang.org/reference/1.11/index.html
I couldn't quite determine the reason of being of the Crystal language. Could someone with experience with the language explain what is its appeal, and why it would be worth trying/learning?
Thanks!
Thank you!
I think the Achilles heel for Crystal is its compilation time on small programs with large dependencies. Note the time to build the entire compiler and standard library is not extraordinary for a large program. It's more like, a small program adding its first few dependencies will find itself pulling in a lot of the standard library to compile, and then will level off in its compilation time.
To illustrate why this may be the case, consider the Crystal feature allowing redefining parts of classes, including ones in the standard library. This is both very useful, and if you think about how it affects features like incremental compilation, immensely complicating.
Here's some practical crystal programs.
This Postgres wire protocol driver is comparable to libpq in performance, and supports a lot of features in the protocol, too: https://github.com/will/crystal-pg/
The Crunchy Bridge CLI: https://github.com/CrunchyData/bridge-cli
Due to it's infancy the packages are sparse, so what some people do is a hybrid approach, where they write their thing in Ruby/Rails and kick out the slower parts to Crystal. This kinda gives the best of both worlds. Crystal (last I checked) had slow compile times, so gives you the dev velocity and package availability of ruby, plus the speed of a compile language when you need it. The compile times on Crystal stay low because you're only writing a small parts/microservices of your application in Crystal.
What's the story on Crystal/Ruby interop these days? I work on a Rails app that does document automation, and I could definitely find some specific < 1000 LOC segments that would benefit hugely from being 1:1 rewritten into Crystal and integrated with the rest of the app.
Http micro service, IPC, or FFI.
There were some attempts to do inline crystal, like what Mojo does in Python, but I don't know if any of them became stable long term solutions.
There's probably a way to get native C ext speed, you can see an old attempt here:
https://www.akitaonrails.com/2016/07/06/trying-to-match-c-ba...
But at any rate, it'll be better than ruby.
- compiled so easy to deploy
- easy to write compared to Rust, when you don't care about being super reliable
- still keeps things typed and better than in Ruby
- lower memory usage than Ruby/Python (and usually an easy 10x jump in performance)
I'm relying on it a lot with simple lambda automation. If I wanted to write an efficient server, I'd probably use rust though.
I enjoy writing it but don’t think there’s any particular reason to try/learn it, unless you happen to also be a ruby dev who prefers compiled, strongly typed languages.