Chapter 3: Writing Your First Crystal Program
Writing Your First Crystal Program
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
:
Put this in it:
And run it with crystal
command:
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:
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.
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.
And to run your program, do the Usual UNIX Thing:
You should see “Hello, world.” print to the screen 50x faster :) Congrats!
Last updated