This is the simplest way to write the Hello World program in Crystal:
But if you feel like it, you can also use some object oriented programming:
Or maybe with blocks:
Each alternative might have a different performance, but luckily all of them are pretty expressive.
Ok, but what’s the purpose of learning a language if we cannot run the damn thing? Let’s see how we do this with Crystal (and let’s assume you already have it installed).
First create a file hello.cr
containing your preferred choice of the previous examples.
Then type in the console:
$ bin/crystal hello.cr $ ./hello Hello World $
The compiled output is a standalone executable without any specific runtime dependency. Neat! Isn’t it?
comments powered by Disqus