Chapter 1: Why Crystal?
You already write software in Ruby. It pays your bills. You enjoy it. Why should you care about Crystal?
Let’s think about Ruby for a minute: what’s its biggest weakness? For me, it’s these things:
Concurrency
Speed
Documentation
What’s awesome about Ruby?
Blocks
Vaguely functional
Syntax is pretty easy
Focus on developer happiness
Get up and running quickly
Dynamically typed
So we could learn a lot from a language that’s easy as Ruby, handles concurrency well, and is fast. We don’t want to sacrifice anonymous functions, pretty syntax, or not making AbstractFactoryFactoryImpls
just to get work done.
I think that language is Crystal.
Now: Crystal is not perfect. It is getting better. But the point is to learn. and using a language that’s very familiar, yet very different, can teach us a lot.
Here’s “Hello World” in Crystal:
Here’s a concurrent “Hello World” in Crystal:
Here’s a rough port to Ruby:
That’s it. Note the stuff that’s similar to Ruby:
Pretty same syntax.
Variables, while statically typed, have inference, so we don’t need to declare types
Here’s some stuff that’s different:
Being compiled and statically typed the compiler will yell at us if we mess up.
Oh, and:
Five times faster. Yay irrelevant microbenchmarks!
Anyway, I hope you get my point: There’s lots of things about Crystal that make it syntactically vaguely similar enough to Ruby that you can feel at home. And its strengths are some of Ruby’s greatest weaknesses. That’s why I think you can learn a lot from playing with Crystal, even if you don’t do it as your day job.
Last updated