# Chapter 3: Writing Your First Crystal Program

## Writing Your First Crystal Program  <a href="#writing-your-first-crystal-program" id="writing-your-first-crystal-program"></a>

Okay! Let’s get down to it: in order to call yourself an “X Programmer,” you must write “Hello, world” in X. So let’s do it. Open up a text file: I’ll use `vim` because I’m that kind of guy, but use whatever you want. Crystal programs end in `.cr`:

```
$ vim hello.cr
```

Put this in it:

```ruby
puts "Hello World!"
```

And run it with `crystal` command:

```
$ crystal hello.cr
Hello World!
```

It should run and print the output without error. If you get one, double check that you have the double quotation marks. Errors look like this:

```
$ crystal hello.cr
Syntax error in ./hello.cr:1: unterminated char literal, use double quotes for strings

puts 'Hello World!'
```

By the way `crystal` command is great for quickly running your code but it’s slow. Each time it compiles and runs your program Let’s see how much does it takes to run that program.

```
$ time crystal hello.cr
crystal hello.cr  0.30s user 0.20s system 154% cpu 0.326 total
```

0.326 seconds for a `Hello World`? Now that’s slow.

Instead of compiling and running again you can compile it to native code with the `build`command.

```
$ crystal build hello.cr
```

And to run your program, do the Usual UNIX Thing:

```
$ time ./hello
./hello  0.00s user 0.00s system 87% cpu 0.006 total
```

You should see “Hello, world.” print to the screen 50x faster :) Congrats!


---

# 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-3-writing-your-first-crystal-program.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.
