If Python is too slow for you, Crystal can be your savior
Learning a new programming language can open your mind in ways you never thought possible. Just like learning a new human language such as Spanish or Mandarin, you learn to think with different words and structures.
You tap into the cultures and communities of the speakers and learn how they see the world. It is enriching to say the least.
The nice thing about programming languages is that the first one you learn is always the hardest. Once you understand basic structures like if clauses and for loops, you’ll see them crop up in many new languages that you may learn.
Discover the future of technology!
Visit us at TNW Conference 15 & 16 June in Amsterdam
And, unlike human languages, new programming languages are much faster to learn. They make more sense and have fewer words – or should I say, commands.
It follows that most programmers and data scientists master more than one programming language.
They may have a main or favorite. But most software developers I know use at least five languages a week, if you count scripting languages.
Most programmers also try to learn a new language every now and then.
It’s part of the job. Coding means staying curious.
The case for Crystal
Crystal, according to the ad, is a language fast like C and slick like Ruby.
The part about its smoothness is true. It is compiled and statically typed, which has its own advantages and disadvantages. However, it is mostly very similar to Ruby in its style.
Personally, I’ve never written a larger project in Ruby. But as a fairly experienced Python developer, Crystal code still looks crystal clear!
Here’s an example of a recursive loop that calculates factorials:

The command sounds a bit strange to people who are not used to Ruby. It’s basically a bad-tasting version of printed matter in other languages. There are some subtle differences between puts and prints, but we won’t go into them here.
Aside from that, this example looks pretty pythonic, right?
It is similar to if clauses:

Aside from the funny expressions that non-Ruby natives are not used to, this is again very readable.
In general, the Crystal’s syntax is cleareven when it comes to bigger and more complicated problems.
Static typing
Crystal is statically typed, but you may have noticed that there weren’t many type IDs in the examples above. That’s because Crystal only requires you to specify a variable’s type if it’s ambiguous.
This practice naturally helps programmers be more productive.
Macros
Statically typed languages tend to be finicky with macros. However, Crystal has a way with them.
As shown in this example, you can use a Crystal macro to modify a piece of code at compile time using static reasoning, based on the contents of another piece of that same code. Try doing this in C++ and you’ll either fail or need more than 500 lines of code.
Or not, you genius? Let me know if I’m wrong…
This comes with some caveats, because, as the saying goes, with great power comes great responsibility. Static typing usually mitigates some danger, but insanely powerful stuff (like the one Crystal allows) somewhat negates this protection.
No zero errors
Speaking of safety, Crystal has additional safeguards elsewhere. Nil is a separate type for the Crystal compiler. So if you try to access a method or container that turns out to be null, the compiler will warn you. This may cause the compilation to fail, but at least you can fix the error before running potentially large code.
No more dependency
If you’ve ever solved a major problem in Python, you probably know something dependency hell resembling.
One Python module can depend on a few others, and once you’ve imported all the modules you need, you realize that different module versions aren’t compatible. Now you need to figure out which versions to use to fit everything together, and all of this can take hours if your project is a certain size.
In Crystal, these modules are called shards and are compiled into your binary executable via static linking. I could go into detail about this, but let’s keep the story short: Dependency management is much, much easier this way.
The big drawback: Crystal is small
Crystal had a while in 2017 when it jumped from place 60 to 32 on the TIOBE index within a month. The reasons for this meteoric rise are hard to say, but it’s quite likely that Crystal’s creators did a lot of marketing at the time and piqued the curiosity of Ruby programmers.
However, Crystal’s moment of fame did not last long. At the time of writing this article, Crystal is nowhere near the top 50 programming languages on the TIOBE index.
Due to its early rise in popularity, some people hoped it could see similar popularity levels like rust.
However, this did not materialize.
Programmers have expressed frustration about example projects or codebases. Also, the documentation seems a bit incomplete. This put new programmers off en masse.
And that’s why the Crystal community is so small that you have to wait a while to get help if you run into problems. There just aren’t that many answers on StackOverflow, GitHub, and the like.
The other downside: Crystal isn’t as fast as promised
Crystal’s creators wanted the language to be as fast as C.
This may be the case in isolated cases. Most of the time though, Crystal takes over twice as long to run as C does.
It’s not uncommon for programming languages (or technology companies for that matter) to have exaggerated mission statements. And to be fair, half as fast as C is still pretty fast.
Nevertheless, Crystal delivers significantly less than its original promise. It’s so obvious that I can’t blame the average developer for being disappointed.
Famous Last Words: Crystal is for experienced programmers only
I love discovering new programming languages, but I prefer well-documented languages with a large and supportive community. Many programmers think alike.
Crystal has had its shot at general public appeal, but overall it has failed in recent years.
This doesn’t mean there aren’t interesting use cases for Crystal. It can be an interesting option for people who work with blockchain technology. You can one fairly powerful cryptocurrency with Crystal.
That said, unless the documentation, marketing, and general community support for Crystal improves, it also won’t be a great option for the average blockchain developer.
If you want to play with a language like Crystal, you’d better bring some experience. Because if you are faced with a problem, there may be no one to help you.
This article was written by Ari Joury and was originally published on Medium. You can read it here.
Contents