# 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:

```ruby
puts "Hello, world!"
```

Here’s a concurrent “Hello World” in Crystal:

```ruby
channel = Channel(String).new

10.times do
  spawn {
    channel.send "Hello?"
  }
  puts channel.receive
end
```

Here’s a rough port to Ruby:

```ruby
10.times.map do
  Thread.new do
    puts "Hello?"
  end
end.each(&:join)
```

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:

```
$ time ./hello
./hello  0.00s user 0.00s system 73% cpu 0.008 total

$ time ruby hello.rb
ruby hello.rb  0.03s user 0.01s system 94% cpu 0.038 total
```

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.crystalforrubyists.com/book/chapter-1-why-crystal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
