I used Crystal to create a web application a 2-3 years ago. It is running great without any problems. There are not that many users (only about 300-400) at any time. Anyhow, I did not touch the application in the last two years, and did not use Crystal in the last two years for anything else. I used Rust to write some simple personal CLI apps, which was fun but also hard. For some reason, couple of days back I returned to Crystal for a CLI app that I am making. I will say this: Crystal is a lot of fun to program in, easy to use and performant all at the same time. I cannot explain the reasons objectively, but it is really a joy to use Crystal. I think I will be using it from now on. I just wish it had a bigger community and as a result more libraries.
Scheme is a small language which achieves expressiveness by allowing you great freedom to push the language into bold new forms.
Ruby (especially with Rails which should almost be considered a separate language) is a big language where simplicity is maintained by informal convention.
Ruby has lots of muddles and messy features, good Ruby code bypasses them.
Ruby was among the first languages I learned, back when there was the possibility of Ruby being a general purpose language and not just Rails. My joy was the result of being able to guess syntax and be right. Nowadays I value reading documentation and IDE level support, so guessing syntax is no longer a joy.
When I saw it, I felt the same way (also using Scheme a lot) and I still feel it is messy. However, what I think might be the reason for it, is that it is difficult to store a lambda in Scheme including its whole environment in an object and send that over the wire somewhere else, on a different machine to run. Perhaps distinguishing between Proc, block and lambda gives Ruby a possibility to treat one of them specially, so that it can do these things easily?
I guess those things are a compromise. Being able to use that concept easily is a joy. The implementation prioritises developer convenience over syntactic purity. It’s a shame we can’t have both, but I accept the trade-off.
While it is not completely impossible to end up (pun intended) with something like this, you usually follow a coding style that avoids it. Kind of like in Ruby.
You have the option to define named methods that yield or to use the short one-parameter syntax where this:
Same argument that I keep on having with people who like
1. gray and darker gray buildings of a tree-less megacity beautiful, with a dash of color
vs
2. those who find small cities/villages mixed with art, trees & colourfully dressed people beautiful.
I'm a Ruby guy and I tried Crystal for about 2 years and absolutely loved it but then had to give up for the following reasons:
1. Too slow to compile (the whole program + the entire stdlib is built everytime you build!). No incremental compilation available.
2. No language server (apparently it's just impossible due to the way the language works). Tbh, I'd be happy with just "Go to definition" but alas, no-can-do!
3. Obscure error messages (macros are to blame here)
4. Weak HTTP server implementation -- making things such as a fetching POST params or uploads incredibly frustrating. Once read the request body cannot be read again.
5. Weak/non-existent Windows support
6. No multicore support
7. Obviously small community
8. Nil handling takes a bit getting used to (coming from Ruby)
9. Error messages are hard to read with overloaded methods wherein just the types are used without any indication of what doesn't match
Overall, if the above changes, I'd switch to it in a heartbeat!
> 3. Obscure error messages (macros are to blame here)
I feel like this is a bit strongly influenced by the macro experience.
Macros are an advanced and powerful feature and naturally more complex to debug.
In general, Crystal's error messages are often praised for their clarity and helpfulness (especially compared to dynamically typed languages, of course).
> 4. Weak HTTP server implementation -- making things such as a fetching POST params or uploads incredibly frustrating. Once read the request body cannot be read again.
The stdlib implementation of `HTTP::Server` is intentionally very bare-bones (many programming languages don't even have such a practically usable feature in stdlib).
Specialized web server implementations are available as shards (https://shardbox.org/categories/Web_Frameworks). They're based on the foundation in stdlib and provide more advanced features.
> 5. Weak/non-existent Windows support
Windows support is pretty stable and almost complete by now.
> 6. No multicore support
Crystal has supported multi-threading as opt-in via the `-Dpreview_mt` flag. It's considered a preview, because it's to be used with care when dealing with data structures that are not thread-safe. But it has proven to work well in production use.
> 8. Nil handling takes a bit getting used to (coming from Ruby)
But once you're used to it, it's sooo much helpful. It just helps to avoid a lot of potential bugs which you would have to take extra care for in Ruby.
> WSL is still the best way to run crystal in windows.
WSL is never the best way to do anything, unless the question is "what is the best way to emulate Linux on Windows?". In all other cases, WSL is literally the worst way to do anything.
This specifically installs the Visual C++ Compiler and the Windows headers so that you can get a command prompt with all that in your PATH. It is not a full-fat VS install. The difference is something like 20-30GBs for the full VS install vs 1-2GB for these specific components.
Have you ever installed Visual Studio? I have. Even just the build tools DOWNLOADS 1-2 GB, as other user mentioned, which is still 10 times what you get with other options.
I also tried it now and then. There are too many places to have concurrency and scaling issues with such a tiny community. The packages and feature sets are thin too.
Alternatives: if you don't mind your eyes bleeding with C++-verbosity and tracking liveness yourself, there's Rust. Sure Go looks cute until you have a million users emailing you trivial questions they should've asked a group.
And if you want something similar to Crystal but with even stricter and more granular semantics than Rust with an even smaller community. there's Pony. It was built around the Orca GC. There's Nim too. Finally, one can use Haskell to built that critical payment service and maintain absolute job security. Meanwhile, the Erlang/Elixir OTP stack stays performant, although no one is quite sure how to package, deploy, and manage its lifecycle properly.
> 2. No language server (apparently it's just impossible due to the way the language works). Tbh, I'd be happy with just "Go to definition" but alas, no-can-do!
The technical challenge is that a Crystal program needs to be inspected as a whole. Simplified, changes in location A can have effects on some completely unrelated location B. That makes it hard to cache intermediary results and a semantic analysis needs to cover the entire program (including the standard library), not just the files that were changed since the last time.
This applies to the responsiveness and memory consumption of the language server as well as the regular compilation process. So this is an important topic, and we're working on improvements. It's a complex topic, but there are some ideas.
Good to know. I've got zero emacs skills and I'm on vscode and nothing works there. From what I understand the lack of type info until the whole program is compiled creates this issue.
> 2. No language server (apparently it's just impossible due to the way the language works). Tbh, I'd be happy with just "Go to definition" but alas, no-can-do!
Crystal powers 90% of the Kagi search backend (reminder being Python). Highlights are great performance and concurency handling. Biggest downsides at this moment are compilation speed (does not take advantage of multi CPU cores) and debugging tools.
Overall our experience has been fantastic (we adopted it while still in beta) and the pace the language is developing is great.
Ah, that's interesting information. I've been a (paid) user of Kagi these last few weeks and I'm really enjoying its snappiness.
Of course, no ads or trackers must help - when I look at the Network tab in developer tools the comparison with a google search is stark. ~4 requests vs. google's ~50.
Wow! I’ve been paying for Kagi for as long as it’s been possible to, love the project & the search results are truly so much better than I’ve gotten from Big G for most queries.
Never would’ve expected it to be using Crystal though! That’s really neat. Are there open source bits? I’d love to see some enterprise-level Crystal examples
We have plans for open sourcing our compontets, including a blog post from our lead dev about how we use Crystal, but never seem to find the time - always some bigger fish to fry.
Just want to say I am very happy with Kagi. I've been a paying subscriber since there was an announcement here a few months ago. The results are typically very good, the speed is unreal, and features like lenses and personalized results are so awesome. It's so nice not having search results filled with Stack Overflow spam sites, and if anything slips through I can block it.
What do you mean by great concurrency? Last I checked multithreading was still hidden behind an experimental compiler flag, which turns me off a bit...
Crystal pretty much provides the same (great) concurrency functionality with light-weight threads and channels etc, but with a cleaner syntax and in my experience less gotchas around closing channels in the wrong place and order etc.
Not OP, but the concurrency model is similar to Go with its use of channels. At the moment the runtime is single-core, but the chosen model should permit multi-core (when they enable it by default) with little to no changes to user source.
Tbh, I prefer it that way round than try to retrofit multi-core onto a model that wasn't designed for it. But yes, single-core feels a bit behind the curve in 2022.
Crystal's concurrency is based on fibers (green threads) which works very well even on a single thread (it scales to multiple threads, as well)
And for many use cases with high parallelization and little shared state (including web applications such as a search engine), multi-threading isn't necessary. Synchronization overhead is a serious performance killer.
You can get much more performance out of running N processes with a single thread instead of a single process running N threads.
Hope a lot of people can see this, detailed explanation come from Crystal core developers.
because a lot of beginners complain that Crystal's fiber doesn't work on multiple cores/multiple threads and then give up using it, it's probably not as important as people think.
Even many beginners mistakenly believe that the Crystal language does not support the creation of operating system native Thread, this is a huge misunderstanding for Crystal.
git clone https://github.com/compumike/crystal-docker-quickstart.git my_app
cd my_app
./d_dev
# docker container spins up in a few seconds... within the container's bash shell, try:
make spec
make && out/my_app
# outside container, you may edit src/main.cr, save it, and then again within container:
make && out/my_app
Out of all the programming languages coming out these days, Crystal is the one I am watching out for. I've never programmed with Ruby, but I have programmed with Python in the past so I really value the focus on programmer friendly syntax that Python taught me. Currently a Golang a programmer and I love the performance plus binary executables!
From my experience so far Crystal feels like a performant language with the wonderful feel of Python. Definitely check this language out if this is the first time you're hearing about it.
However it really needs a bit of “wow” factor to take off.
We’ve used it here and there in dribs and drabs but don’t see a reason to use it in a new project when there is Elixir and/or Rust.
Elixir brings the easy to use concurrency almost automatically. This and other features make it almost unbeatable for web and backend stuff.
Rust is just as fast as crystal. Albeit harder to grok.
Python was literally saved by the numerical libraries. Or there would not be real reason to keep using it.
I keep one weather eye open on crystal to see how it’s doing but have seen no real reason to start a new project with it as yet.
For me the syntax is not reason enough as yet. Elixir is maybe easier and functional to boot. Being object oriented in 2022 is not a good reason either.
I’m an old rubyist and I wish Crystal the best. I’ve been following it since it was a gleam in the eye, But … why? And for what??
That provides you the flexibility of having union types (variable may be `Thing1` or `Thing2`) for generic purposes, AND type-safetiness (is that a word?) when dealing with specific paths of your program that apply differently to some of the subtypes of the variable.
I think Swift and Kotlin support (some of?) that now. It was really new for me back in the day (around 2014?).
But that's from a coding point of view - not that much about niches, as you talk about.
Now, all we need for crystal to succeed is numpy, scipy, something pandas-like, and of course matplotlib (not plots, matplotlib).
By the way, how are we on data-science friendly IDEs? Debugging? Automatic thorough documentation generator? Tooling in general?
Is the time to first plot fast?
Data science is a domain crystal could excel in. Having both an approachable syntax and the feedback that the compiler and type system provides makes it an excellent companion for that work.
I've tried a few times now to do data science in a statically typed language, and I just haven't enjoyed the developer experience. In general I tend to think the advantages of dynamic typing are overblown, but this is one problem domain where it seems to be indispensable.
ML and data engineering is a different story, of course. Also, I wouldn't be surprised if something clever could be done with a structural type system.
Why would you want "a little" static typing? What does that mean? I used to write python in vim and hated it, made tons of mistakes that were time consuming to find. Type hinting religioussly and using pylance in vscode sped me up a great deal. But I still make those mistakes sometimes, and they are still troublesome to find. Sometimes they pass unit tests because the types are off in the test too. I think a compiled strongly and statically typed language with excellent type inference is the best of both worlds, freedom with a safety net. The problem with interpreted or jit languages is that even with strong typing, inference won't save you until runtime. I'm enjoying julia, but finding type errors at runtime is a downside.
>... numpy, scipy, something pandas-like, and of course matplotlib... Where I work, we desperately need a fast python.
It sounds like Julia would be a better fit than Crystal?
Ironically they have similar problems: compile/start-up time (though crystal has working ahead of time compilation - AFAIK Julia developers are still working on speeding up "first run" in various ways).
I used Crystal every day for 2 years.
It is for me one of the best languages. Fun and powerful but there are some big problems, I switched to Elixir.
Among the problems :
- A too long compilation. For 2 projects, the compilation in dev env takes more than 30 seconds for each compil, the developer experience is dead at this cadence.
- IDE integration: auto-completion, go to def, API docs, etc works when it wants (almost never).
- The community is too small which results in a lack of docs, examples, help. I spent days searching in Github projects, just to see examples of basic things.
- Instead of focusing on a main framework that makes everyone agree, everyone makes their own framework, their own libs (including me). The result is a lot of time and energy spent on duplicate packages and frameworks that are not necessarily maintained.
I continue to follow the evolution from afar, one day it may be possible to integrate Crystal in WASM, acceptable compile times, maybe a productive main framework :)
For someone like me who never managed to make himself enjoy the Python syntax, Crystal seems like a great choice, and I realize I just forgot about it recently. If there's enough libraries available I might just dive in.
Nim and Crystal feel like they are in exactly the same space? GC, fast, single executable compilation without runtime (I would also throw Go into this list).
Nim's new ARC gc, which will be default soon-ish in 2.0, does not have a "runtime" as commonly understood.
It is fully deterministic, so it simply injects alloc/free calls in the generated code at compile time. It even has an option that can show you where the calls are injected.
Everything has a runtime nowadays. Even C, even if it isn't all that large (including for example the memory structures necessary to keep malloc and free working).
I think that’s too expansive of a definition of “runtime.” The context required by C and Rust programs is generally internal, meaning that interacting with the dynamic allocator doesn’t require the programmer to be aware of the implementation’s invariants. This is in contrast to a managed language like Java, where using a managed object from C via JNI requires coordination with the runtime (which in turn preserves the invariants).
But you have to know that as well for C - there are for example several Linux system calls you really should not call manually because that would fuck up the internal state in LibC. Yes, the runtime is really small, comparatively speaking, but it is still a runtime.
Which system calls are you thinking of? The only ones that I can think of would be brk(2) and sbrk(2), but any recent libc should be resilient to calls to those.
That being said, I'll grant that the distinction between "tiny runtime" and "no runtime" isn't useful and that C can be said to have a runtime insofar as most systems provide a `crt0` or equivalent.
Pony does stricter sharing semantics than Rust (multicore) with actors and allegedly one of the fastest GCs ever developed. Its community is even smaller than Crystal's. Pony was developed essentially as a PoC to demonstrate the GC.
You can ditch Nims GC and runtime and bring your own if you want. Of course you'd lose access to most of the stdlib but this is why Nim can be used and is popular for embedded / bare metal.
Tmk Crystal still lacks Windows support as well and probably other os's / archs's compared to Nim
Rust doesn't have a garbage collector, meaning you have a steep learning curve around the borrow checker. Zig aims to be a C replacement, with manual memory management as well.
Nim is very close to Crystal. Some parts that might lead you to prefer Crystal however:
- Nim compiles to C code, meaning Nim is coupled to what C can do. I find compiling to C to be distasteful, C is not meant to be a compilation target. We should be getting away from C, IMO. Nim is limited to what C can achieve, and the design of the language trends towards "here's how this translates to C" as a result. Compiling to C is also an extra layer of abstraction, as now for instance with debugging you have to go through the C layer. Crystal like Rust uses LLVM
- Crystal also uses Ruby syntax, which many prefer. I have grown to dislike semantic whitespace such as how Python works, so this is a plus for me.
- Crystal has a garbage collector, period, and leans into that. Whereas Rust, Zig, and Nim want to give you complete control over memory, Crystal is more focused on being a better high-level programming language, competing with the likes of JVM/NET/Go/Ruby. This focus is likely Crystal's main edge. The only other single-executable opinionated GCed language is Go. Crystal's type system is much better than Go's. If Crystal can reduce compile times and capture some of Go's pragmatic aura, it will see more success.
Looks interesting! I'm always open to a statically type checked language.
This isn't about the language, but I was surprised to see that Nikola motors is a sponsor. Wasn't that company a fraudulent Hydrogen Fuel vehicle startup[1]? I wonder what the story is there- I find it hard to imagine anyone would be doing much software engineering at the company in the first place, even if it *were* working on the technologies they claimed to.
Yeah, and Meta uses Rust and contributed to a mass atrocity in Myanmar and is facing a $100BN+ lawsuit. Does that mean we should all stop using Rust because Meta is not only using it but also sponsoring the Rust Foundation as well?
That could be possible considering much of the language seems compatible. However, Crystal has incompatible accessor syntax for some reason. And concurrency is handled differently unless rails uses fibers everywhere. At this point they are way too different to just get away with syntax find/replace, it would require structural changes as well.