5 ms·
From the landing page (and trying a few tutorials): https://crystal-lang.org/reference/1.11/index.html https://crystal-lang.org/reference/1.11/index.html I co
by fransje26 3y ago
From the landing page (and trying a few tutorials):
https://crystal-lang.org/reference/1.11/index.html 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!
- helen___keller 3y agoCrystal is basically taking Ruby and adding compilation and a strong static type system. 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.
- WJW 3y agoWhy would a language need a specific reason to exist? It's a nice language with Ruby-ish syntax, strict typing, a go-like runtime and it compiles down to something quite fast if you take a little bit of care.
- aeturnum 3y agoTo me, it kind of sits between Golang and Rust in terms of intent. I think the goal is to deliver reliable runtime characteristics at the speed of a compiled language, while generally only demanding as much specificity as higher-level interpreted languages (i.e. Ruby). For me I reach for it when I want something that's fast (like go or Rust) but which I can write quickly (like Python or Ruby).
- ukd1 3y agoReason; no idea - but the appeal for me is it's very ruby-like, and super fast (except, compiling). Some programs I've moved from ruby use >10x less memory, and are generally faster. It's mostly as a nice to write as ruby, except the compile time. Concurrency is very go-like, and there are a reasonable amount (not ruby-like though) level of libraries for use.
- fransje26 3y agoI'm not familiar with Ruby, and the link to Ruby had completely escaped me. (What's in a name, huh?) Thank you!
- orthoxerox 3y agoAs far as I understand, work on Crystal started when Ruby on Rails was the hottest web framework. The original purpose was going to be running your RoR apps that outgrew MRI. Yes, code would have to be adapted to run on Crystal, but that would be much easier than rewriting everything in a completely new language.
- DistractionRect 3y agoMy understanding, it's ruby like, but statically typed and compiled. Basically instead of trying to retrofit ruby with these features without breaking things (like Shopify and friends do with JITs, AOTs, sherbert, etc), this is bottom up approach around these features. 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.
- Toutouxc 3y ago> where they write their thing in Ruby/Rails and kick out the slower parts to 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.
- DistractionRect 3y agoAFAIK, it's the same as any other language w/ Ruby. 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-based-fast-blank-with-crystal https://www.akitaonrails.com/2016/07/06/trying-to-match-c-ba... But at any rate, it'll be better than ruby.
- deleted 3y ago[deleted]
- fdr 3y agoIt generates efficient code (similar to a C program, e.g. you could write a reasonable ray tracer), and is concise. Many Ruby programs would not see a size expansion from being written in Crystal. It's also good at interoperating with C programs; it's employs LLVM in a fairly orthodox manner (so, for example, if you run `perf` under Linux, you will get good symbolic output) 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/ https://github.com/will/crystal-pg/ The Crunchy Bridge CLI: https://github.com/CrunchyData/bridge-cli https://github.com/CrunchyData/bridge-cli
- viraptor 3y agoFor me that's the sweet spot for: - 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.