Crystal Clear

[linkstandalone] Crystal Clear

Do you want to have the productivity of a scripting language while still having the benefits of a statically typed and compiled language? Well, Crystal may interest you. I spend a fair amount of time programming in Python and while I enjoy the languages productivity and all of the wonderful libraries available, there are some things I miss. First of all is speed. Python isn’t exactly known for its speed. While you can use Pypy or write your important code in C and use the FFI, that kind of defeats the purpose of using the language in the first place. Also, I can’t say I’m very much a fan of the syntax of Python. I have programmed in Ruby some in the past, and its syntax has always held a special place in my heart. Someone (likely some random person on IRC) once wrote about Ruby that, “Ruby is what happened when Lisp got lonely and Perl got drunk”.

Crystal takes the syntax of Ruby, adds types, and compiles it down to efficient machine code. Their motto is “Fast as C, slick as Ruby.”. There is no manual memory management. They use the Boehm garbage collector. This is a whole other interesting subject and while there are some cons to using this tool, I can understand why they chose to use garbage collection. Dealing with memory management is a tedious process and slows down the entire development process. So where does this language fit in? Who is it geared towards?

The obvious candidate is Ruby programmers. I could see maybe some Go programmers using the language, Python devs, PHP devs, maybe even D lang devs. D is another one of the languages I have been looking into most recently and I can see a lot of parallels between the two languages. Crystal seems to be geared towards web services in general. There is a simple HTTP server, and built in concurrency support via Fibers. They are working on implementing parallelism, and the claim is that it will be ready in 2018 [Update: There is, which is parallelism as a shard]. There is a growing pool of libraries available for the language.

Rather than gems, Crystal has shards (heh.).

Features: - rspec testing - reuse of ruby code - shards - community


For a pet project I wanted to write and RPN calculator in Crystal (think dc). If you are curious to check out what it is like you can peek at some of my code..


So how fast is Crystal? There is a nice GitHub repo where a user did some benchmarking of various algorithm implementations. In these synthetic tests the language overall appears to perform very well for being a garbage collected language.


Crystal is still a new language. It is considered alpha level software. This doesn’t mean that you shouldn’t use it though. There a few companies who are using Crystal code in production. Give it a shot. I don’t know that I would use this as my main language of choice, but when I want to write Ruby code I’ll likely write more Crystal code instead!