Learning a new programming language can open your mind in ways you never thought possible. Just like learning a new human language like Spanish or Mandarin, you learn to think with different words and structures.
You’ll explore the cultures and communities of the speakers and learn how they see the world. It is enriching, to say the least.
The beauty of 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 pop up in many new languages you might learn.
Get your tickets for TNW Valencia in March!
The heart of technology comes to the heart of the Mediterranean
And unlike human languages, new programming languages are much quicker to learn. They are more logical and have fewer words – or should I say commands.
It follows that most programmers and data scientists know more than one programming language.
You could have a main or favorite page. 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 from time to time.
That comes with work. Programming means staying curious.
The case for crystal
Crystal is advertised as a language as fast as C and as sophisticated as Ruby.
The part about its smoothness is true. It is compiled and statically typed, which has its own advantages and disadvantages. Most importantly, it’s very similar to Ruby stylistically.
Personally, I’ve never written a major project in Ruby. But as a fairly experienced Python developer, Crystal code still looks crystal clear!
Here is an example of a recursive loop that computes factorials:
Faculty calculation in Crystal. Image by author, code adapted from Crystal by Example
The command sounds a bit strange to people not used to Ruby. It’s basically a tasteless version of what’s printed in other languages. There are some subtle differences between puts and print, but we won’t go into detail about them here.
That being said, this example looks pretty Pythonic, doesn’t it?
The situation is similar with if clauses:
If clauses in Crystal. Image by author, code adapted from Crystal by Example
Again, aside from the funny puts expression that non-Ruby natives aren’t used to, this is very readable.
In general, Crystal’s syntax is clear, even when dealing with larger and more complicated problems.
Crystal is statically typed, but you may have noticed that there weren’t many type specifiers in the examples above. This is because Crystal only requires you to specify a variable’s type if it is ambiguous.
Of course, this practice helps programmers be more productive.
Statically typed languages tend to be finicky about macros. However, Crystal has a way with them.
As shown in this example, you can use a Crystal macro to change a section of code at compile time through static reasoning based on the contents of another section of the same code. If you try this in C++ you will 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 reduces some dangers, but insanely powerful things (like the ones Crystal allows) undo that protection somewhat.
No zero errors
Speaking of security, Crystal has extra 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 can result in a compilation error, but at least you can fix the error before running some potentially large code.
No more dependency hell
If you’ve ever solved a big problem in Python, you probably know what dependency hell looks like.
A Python module can depend on a few others, and once you’ve imported all the modules you need, you’ll find that different module versions are incompatible. Now you need to figure out which versions to use to make everything fit together, and it can all take hours if your project is a certain size.
In Crystal, these modules are called shards, and they are compiled into your executable binary via static linking. I could go into detail on that, but let’s cut the story short: managing dependencies is much, much easier this way.
The big downside: Crystal is tiny
Crystal had a moment in 2017 when it jumped from 60th to 32nd on the TIOBE index in just a month. The reasons for this meteoric rise are hard to pin down, but it’s quite likely that the creators of Crystal did some considerable marketing and piqued the curiosity of Ruby programmers at the time.
Crystal’s moment of fame didn’t last very long, however. At the time of writing, Crystal is still a long way from being among the top 50 programming languages in the TIOBE index.
Due to its early popularity, some people hoped it could achieve similar popularity to Rust.
However, this has not come true.
Programmers have expressed frustration with sample projects or codebases. Also, the documentation seems a bit incomplete. This has put off new programmers in droves.
Because of this, the Crystal community is so small that when you run into problems, you have to wait a while to get help. There just aren’t that many answers on StackOverflow, GitHub, and the like.
The other downside: Crystal isn’t as fast as promised
The creators of Crystal wanted the language to be as fast as C.
This may apply in individual cases. Most of the time, however, Crystal takes about twice as long to run as C.
It’s not uncommon for programming languages (or tech companies) to have exaggerated mission statements. And to be fair, half as fast as C is still pretty fast.
Still, Crystal clearly delivers on its original promise. It’s so obvious that I can’t blame the average developer for feeling let down.
Famous last words: Crystal is only for experienced programmers
I love exploring new programming languages, but I prefer well-documented languages with a large and supportive community. Many programmers feel the same way.
Crystal has had its attempt at mainstream appeal, but overall it’s failed in recent years.
That doesn’t mean there aren’t some interesting use cases for Crystal. It could be an interesting option for people working with blockchain technology. Crystal allows you to create a fairly powerful cryptocurrency.
That being said, unless the documentation, marketing, and overall community support for Crystal doesn’t improve, it won’t be a good option for the average blockchain developer either.
If you want to play with a language like Crystal, you better have some experience. Because when you’re faced with a problem, there might be no one there to help you.
This article was written by Ari Joury and originally published on Medium. You can read it here.