If you’ve used Ruby before, then this will be instantly recognisable as a function to calculate the nth Fibonacci number. It’s so recognisable that if you were to run this with Ruby the program would run correctly. Of course you can run it with Crystal too.

Pretty amazing, right? And Crystal is orders of magnitude quicker than Ruby in this test. Of course, the Fibonacci sequence is a terrible benchmark and this isn’t exactly a fair test either, but it’s interesting to see the similarities. As you start to dig into Crystal, however, the differences between this language and Ruby start to emerge.

Let’s do that now and make some calls to the Twilio API using Crystal.

Getting started with Crystal

To use Crystal, you’ll first need to install the compiler. For Linux, follow the installation instructions in the Crystal docs. If you’re on a Mac you can install Crystal with homebrew with the following: