The old slogan used to be "Slick as Ruby, Fast as C" but I'm guessing that just invites people to constantly compare runtimes to C and be like "look! it's 50% slower when blahblahblah" when comparing 10ns to 15ns.
That said, I do think they should put the "why" in clear text. Ruby made no apologies for being a language "for the programer" while Crystal is meant to be a language "nice for the programmer with slick syntax and a modern type system AND compiles to very efficient bytecode that's comparable with C (at the cost of more time spent compiling to reach those goals)"
I'd love to see a "why" somewhere in there... telling me that its syntax is similar to Ruby and that it has a type system (which Ruby also has as of version 3, yeah?) isn't particularly helpful in telling my why the language is compelling.
I don't really see a "why use Crystal instead of Ruby" (or any other language, really) explanation anywhere. Maybe the things listed on the main page are meant to be that? Even if it's not on the main page a comparison would be nice in the docs (https://crystal-lang.org/docs/) or the reference (https://crystal-lang.org/reference/)
Crystal is a programming language with the following goals:
Have a syntax similar to Ruby (but compatibility with it is not a goal)
Statically type-checked but without having to specify the type of variables or method arguments.
Be able to call C code by writing bindings to it in Crystal.
Have compile-time evaluation and generation of code, to avoid boilerplate code.
Compile to efficient native code.
Why?
We love Ruby's efficiency for writing code.
We love C's efficiency for running code.
We want the best of both worlds.
We want the compiler to understand what we mean without having to specify types everywhere.
We want full OOP.
Oh, and we don't want to write C code to make the code run faster.
Ruby's type system is completely optional using separate definition files (except Sorbet, which isn't part of the core language), while Crystal's is built in and required.
Crystal is like Ruby but not dynamic, with macros, without reflection, with arbitrary API changes to the core types that are shared, with value/reference type dichotomy, compiled, and faster.
Or, with apologies to the late Douglas Addams, Crystal is almost, but not quite, entirely unlike Ruby.
The language itself is very interesting. I've dabbled a few times and really like the clean ruby-esque syntax.
What puts me off delving further is the lack of support in various editors / IDEs / Treesitter etc. I think the core development team should really devote some resources to this, as I'm sure I'm not the only one deterred by this dearth of tooling.
As per my original post, while the lack of tooling is my biggest pain point around the language ecosystem, inside the language itself, my main gripe is with the error messages. I find them quite impenetrable a lot of the time. Which is not ideal when confronting a new language.
Crystal could take a leaf out of V or Rust's book here. Whatever you think of the languages themselves, the error messages are top notch. Errors that say "Ah. I see what you were trying to do here. Maybe you should try this instead?" are so much more helpful than "Why on earth did you do that?!"
Honestly, until they provide some more support at least in the editors and IDEs field and support native Windows Crystal is not going to be more than a fun tool. I like it, because the general developer experience I had was really pleasant, but I cannot really use it for work.
It's kinda working right now, with some missing features like exceptions raising and catching, block closures, c-library binding (only libc works IIRC).
How much of that is libevent vs. io_uring and not epoll vs. io_uring? It would also be interesting to compare to other frameworks/languages on the TechEmpower Web Framework benchmarks.
BLUF: I love crystal and can't wait for it to get the attention I think it deserves.
To give a bit of history of myself and programming languages, I first started as an EE/CS major working with ASM/C/C++/Matlab for EE and C++/Java/Lisp for CS. Up until graduation, it was just a given that programming languages were just a concession given to you so you didn't have to write assembly. OO in the form of C++/Java was the "better alternative" to imperative C. Lucky me.
Then I heard about Ruby and Ruby on Rails. After reading "The Ruby Programming Language" and working through the examples, I was blown away by the idea that a language could be for a programmer and be a way to express ideas rather than something we translate ideas into. Metaprogramming and mixins and Procs oh my.
Then I started working through Project Euler questions with Ruby and it all came crashing down with the reality of Ruby's runtime. Ruby gave me expressiveness but just could't give me the speed of my equivalent C/Java code. Granted, I was definitely doing very sub-optimal algos but even then, C/Java just didn't care and gave the answer in seconds, not minutes.
Since then, Java & JS have paid my bills. I've seen the popularity of Ruby die as Rails fell out of style when Twitter moved away.
I've messed around with Crystal, trying to work through the problems in "The Go Programming Language" in Crystal and finding that Crystal is a beautiful language and fast as hell. That said, there's always a trade-off right? Crystal's trade off is in compile time, especially with --release. However, I think that's a reasonable trade-off since your release builds should be on a beefy server and it could save you $$$ if it means your actual production servers can be lean as hell. That said, I'm also aware that this problem is exactly one that the Go language was meant to address (C++'s exponentially growing compile time).
Crystal definitely needs:
1. IDE/Debugger support, understandable for a new language, but the language should be "finished" and tooling needs critical attention
2. Libraries. The classic problem of any new language.
3. Major sponsorship (would greatly help with point 1 & 2)
So I am currently making an api server in Crystal and I adore this language. I would add some pros/cons for folks who are interested in trying it out;
Pros:
- Elegant syntax. Crystal is highly inspired by Ruby and it has a lovely elegant syntax. Syntax is important to me and the clutter of symbols and the busy syntax is why i struggle with Rust.
- gorgeous type system. F# is the only other language I can think of which has this lovely and complete a type system. The way Crystal handles Nil (its a type) just feels great in practice.
- Perf wise, Crystal is blazing fast. It seems to be marginably faster than most compiled languages like Go, Nim etc in the benchmarks. Though at that level the difference isn't much.
- batteries included stdlib
- decent documentation. It could be better but imo its good enough. I rarely have to look beyond the documentation if I get stuck anywhere.
- small but amazing community. the folks in the community like Ali, blacksmoke, Oleh, Ary and many others etc are super helpful and always ready to teach a newcomer.
Cons:
- Lack of Windows support. The biggest elephant in the room. the good news is that this is under development and even in this release a lot of progress towards a Windows event loop was made. But if you are going to do web dev, you can always go with wsl for the compilation as most of us do.
- Slow compilation speed. Its faster than Rust/C++ but if you are coming from an interpreted language the 5-10 seconds it takes to compile your small project rankles a bit.
- DB drivers need to be better. They currently don't support pipelining, ssl, async etc. Not a big deal as the Crystal drivers are performant enough. but I think if these were there, Crystal would get at least 20-30 ranks in the techempower Fortunes benchmarks.
- IDE tooling is not yet there.
- Small community and hence lack of community packages. Often stuff will have to be done by hand. Things like oauth, openssl conversions etc will need some work from you.
- no http/2 support
- The lack of a BDFL and corporate sponsorship. This means that the language growth is less structured and highly dependent on the community leaders.
Here is an old comment I wrote about Crystal on HN. it is still as true today as it was then;
----------------------------------
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 (except perhaps f# and nim) seems to have the same effect on me.
My favorites Crystal features are its do-end syntax, dat sexy type system hnnnnghhh... , domain modelling using sum types, null checking using types, ultra simple OOPs, insanely productive std and its sheer performance.
The bits about the language I detest are the overuse of macros, the utter lack of any platform (windows, http/2 etc.) or tooling improvements (IDE support, slow compilation). The core maintainers are amazing but have a weird obsession with just refactoring the language semantics. Things which really would matter for any language usage are just relegated to GH issues which haven't had any comments on it for months (if not years).
The lack of a BDFL and corporate sponsorship really hurts Crystal bad. Its a language without directed growth. For a language which seems to be used the most for web servers, it lacks http/2, db pipelining and async db drivers. There have been plans for redoing the http module for years but it hasn't been done yet.
Yet, I love this language despite all its shortcomings. I find it to be one of the most readable languages out there. The community is full of amazing individuals who are ever helpful and welcoming. The core maintainers are super talented developers who really value quality of code.
Right now I am working on an api servers and have 3 early implementations - one in Rust-actix, one in pure crystal (no framework) and one in Go-Fiber. The joy of using Crystal and feeling like I am in control of the project are reasons which are pushing me towards using Crystal for the project. But I know that by the next few years, we likely still wouldn't have
http/2, async drivers, nice IDE support and many other features that I really need.
And so, I will likely have to go with Go. (Rust syntax is just too complex for my taste. And I am not talking about the celebrated borrow checker).
I like go.
Go is simple.
Go is Productive.
Go is... just not Crystal.
-----------------
Epilogue: I did not go with Go. Its error handling and opinionated formatting turned me off so much that I have returned back to crystal. :/
What's stopping you from going with Nim? Honestly curious, I have my own love-hate with that one, so I have some guesses, but I'd find it fun to "fact check" those and compare opinions :)
Mostly a lack of good web frameworks which are performant and have good devex.
Jester the main Nim framework doesn't even have a webpage and that doesn't inspires any confidence.
Httpbeast may be fast but it feels like just a PoC. It doesn't even have docs.
Prologue is the most promising one IMO, but it is still very new and its performance isn't as good. But I do keep a check on it.
Overall, Nim needs something like Lucky, Athena, Azu Toolkit etc to feel like a serious web dev language.
That said, I have always been thinking of rolling with just the stdlib stuff so I may do that one of these days.
I agree that a nice website would be great to have for Jester (and I do intend to create one), but I think you place far too much importance on Jester having one. Jester/HttpBeast is used in production by big web apps[1], why doesn't this inspire enough confidence and possibly even more than the other web frameworks you've mentioned?
I think there is an inherent bias that all humans have for shiny design, you should definitely keep it in mind when choosing a technology.
I understand that it is frustrating to hear somebody telling you that they lack confidence in your tool simply because it «lacks a webpage», maybe after you have spent so much time creating and polishing it!
However, considering the huge amount of languages/webframework pairs (D+Vibe? Nim+Jester? Crystal+Whatever? Go? Rust? etc.) available today, it is understandable that people pick simple criteria like this to decimate their number of choices. The alternative to start playing with each tool for a few days to rank them and pick the best choice is obviously not possible.
For me, it’s also because of IDE tooling. Nim syntax supports so many different call styles that when you press dot for autocomplete you always see so many options to the point it’s not helpful anymore. I’d love to know if there’s a way around that issue.
Most of this is still true, but this is the most balanced review of Crystal I've have read so far here.
Although I use Rust most of the time, I keep having a look at Crystal and appreciate its simplicity and can get alot of things done with it rather than fighting with the borrow checker.
Very happy to see it reach 1.0 and further.
> and corporate sponsorship
Well there are companies (and smaller individuals) that are still sponsoring it every month. [0]
Compared to the Google sponsorship of Go and the Amazon sponsorship of Rust, a few thousand from unknown vaporware companies isn't really a level comparison.
(disclaimer: I was once a coffee sponsor of Crystal myself)
> a few thousand from unknown vaporware companies isn't really a level comparison
I see, So: "If a company that I don't know about is putting money into a language, it's doesn't really fit my definition of 'real' sponsorship"
It still counts as sponsorship whether if it is a FAANMG company or a tiny startup and there are companies that use Crystal that are sponsoring it monthly. No need to move the goal posts here.
Probably the Golang people did the exact same comparison to Rust when that reached 1.0 in 2015; way before the Rust foundation was formed or any company sponsoring Rust other than Mozilla.
So perhaps Ocaml (The language that Rust was first written in) doesn't count as well since that has a couple of so called 'unknown vaporware companies' and zero FAAMNG companies on the list of 'sponsors' then? [0]
You're right, the name of the company or FAANG-ness doesn't matter. I didn't claim only FAANG sponsorship matters, but it is important and even more important, the amount of $ does.
I also never said it wasn't "real" sponsorship or didn't count. Don't put words in my mouth. I said it isn't a level comparison.
> any company sponsoring Rust other than Mozilla
Mozilla? never heard of them. I only know FAANG apparently /s
Also, Ocaml has supporters such as Bloomberg and Mitsubishi. Not exactly mom-and-pop startups.
Again, I'm not exactly sure what you're arguing. I'm literally a sponsor of Crystal. I put my money where my mouth is.
> but it is important and even more important, the amount of $ does.
Also you:
> Also, Ocaml has supporters such as Bloomberg and Mitsubishi. Not exactly mom-and-pop startups.
Perhaps Jane Street is also another mom-and-pop startup then. /s
So they (Bloomberg, and Mitsubishi) somehow matter because they're "Not exactly mom-and-pop startups" even though you also said, "the amount of money they are giving matters". Given the OCaml sponsorship levels [0], Bloomberg (Silver) donates around $1250 - $2084 a month and Mitsubishi (Bronze) around $416 - $1249. That is still less than the monthly amount that either Nikola Motor or 84 Codes is putting in combined.
Nikola Motor isn't not a startup and still sponsors and uses Crystal. It seems that they have alot of money left over every month to throw at Crystal even before it reached 1.0.
> I said it isn't a level comparison.
Then congratulations to Crystal for getting sponsors (and companies sponsoring it) even before 1.0 then. They'll probably get more even after 1.0 then.
Never saw that in Rust before the foundation was formed (which should have been done earlier) since its actually Google again (not Mozilla) feeding the majority of the sponsorship funds to Mozilla.
> Again, I'm not exactly sure what you're arguing. I'm literally a sponsor of Crystal. I put my money where my mouth is.
Good and so do the companies that still use Crystal to this day even before 1.0. At least individuals can sponsor it as I mentioned previously. Unlike Go, whose fate is ultimately in the hands of Google for any decision they make for the language.
This is an excellent summary, at least for the pros and cons.
I find your take on the project leadership interesting, because it is a spot-on description of everything I found to be wrong with Elm. That BDFL was/is not so benevolent. Or maybe he’s well-meaning but terribly annoying. And the language has a mich better claim to being dead than Crystal, where I had not noticed any loss of momentum or activity on GitHub.
(You may well be right on those points as well, as you are clearly more knowledgeable about the dynamics)
> Elegant syntax. Crystal is highly inspired by Ruby and it has a lovely elegant syntax.
Agree 100%. I still haven't written any Crystal, but I read through parts of the code-base, out of curiosity, and it is some of the most pleasant compiler code I've ever read.
I absolutely love Zig, but based on what they praise Crystal for, I don't think they'd enjoy it. Polar opposite syntaxes, do-it-yourself type system, batteries-not-included standard library, and manual memory management? Probably not what they're looking for.
i am intrigued by Zig and have been following it for a while. But i plan on seriously trying it out after the following are availabe; self hosted compiler, http server (or at least a standardized interface) in stdlib and a package manager. Otheriwse the language would not be productive for my needs.
Was Crystal the power behind Trevor Milton's famed "HTML5 supercomputers", then?
Crystal looks nice, faster, more beautiful and ergonomic than Go, but I don't see its application for embedded use-cases, which is where I would think Nikola would target any special sauce, if it has any.
I'm pretty sure HN is not the place to post corrections for an article; have you tried any of the channels on https://crystal-lang.org/community/ instead?
My dislike for Ruby was one of the main reasons I left my last job... but I think that opinion will probably get an angry mob after me here on Hacker News haha. And honestly, it could have just been the way they were writing Ruby there that drove me to leave, but the language has left a sour taste in my mouth.
There was too much "magic" going on. I could never figure out where variables or functions were coming from. Sometimes I would have to sit down with our local Ruby guru (a principal engineer who has been working with Ruby for years and years) and it would take us the better part of an afternoon to track down what a function call was doing.
Again, that all could have been a side effect of horribly written Rails code where I was working. The Ruby guru I mention above would often lament about how bad our Ruby codebase was. To me, it just showed "wow it's really possible to write code this bad in this language" and left a sour taste in my mouth.
I usually prefer TypeScript for scripting things. Being able to run it via node and in the browser is a killer feature and I have many small libraries I've written that I reuse in a lot of personal projects. Sometime I use Python but I'm not a huge fan of Python's version and dependency management.
For anything that's not destined for the browser that require speed or a larger codebase (i.e. backend services) I don't think you can go wrong with the JVM. I prefer just plain Java, but also have used Scala and Kotlin extensively and they're all great for speed, collaboration, readability, testability, and have robust ecosystems.
And just to be clear, to_s will return a string, but it will definitely not do the craziness of converting an integer into an English representation of the number!