I've recently come across the Crystal programming language. Crystal is a statically typed programming language with a Ruby like syntax. I thought it might be useful to share my experiences so far. Here goes:

  • The thing that attracted me to Crystal in the first place is something I haven't seen discussed much elsewhere: You can crystal build your way to a compact and completely stand alone executable, an executable that doesn’t rely on something else — specifically a Ruby installation. One of the things that I do with Ruby is write little utilities (see, for example expletive and md_inc). The ability to produce an executable that just works is great for my purposes.

  • It's also not bad that the executable is likely to be much faster in Crystal. As I say, I'm just getting my feet wet, but I have ported expletive over to Crystal. When built with the –release flag the Crystal version runs nearly an order of magnitude faster than the original. Yes, that’s 10X. Speed ain't everything, but it's something.

  • Crystal has an interesting take on static typing and in particular type inferencing. To be honest I'm still trying to build a model in my head of how it all works. I do think that Ruby programs built with classic OO tech like classes and subclasses and included modules will be the least problematic to port. For example, I ported expletive, which is pretty traditional object oriented techniques to Crystal very quickly.

  • I’ve spent some time trying to understand how the Crystal typing system works when you are using lambdas, and I think porting Ruby code with lots of lambda use is going to be more of a challenge, but not terrible. We Rubyists (well this one anyway) are just not used to thinking about the types of things returned from lambda calls.

  • Most challenging are Ruby programs (and Rubyists!) that use a lot of metaprogramming. So for example, my md_inc utility is just full of instance_eval calls and is going to need some major rethinking to bring to Crystal. Which brings me to macros. Crystal’s macro system is interesting, and to be honest, fun to play with. I do agree with others who have said that macros can soak up most of the work that you might otherwise do by resorting to meta-programming. I've seen this in the Clojure world where there are lots of meta-programming facilities available but most of the time it is cleaner to do it with a macro. But I’m still thinking about macros in Crystal.

  • Biggest annoyance so far – and this is a silly one – is not being able to use 'single quotes for strings'. It's not a bad language decision, it's just not compatible with the software loaded into my fingers.

Overall I think Crystal is well worth a look, especially if you are a Rubyist without much experience with a ”compiles to a real executable" lower level language (like C) or with static typing. It's an easy way to see how the other half lives.

Personally I'm looking forward to learning more.

– Russ