Today, I have started exploring new programming language called Crystal.
Why Crystal Language:
- Speed: Crystal is compiled language based on LLVM framework so it directly gets executed on runtime.
- Syntax: As Crystal lang tagline suggest Fast As Slick as Ruby, Crystal uses ruby language like syntax to write code.
- Statically Type check: Crystal is statically type checked language so any type of errors will be shown or caught on compile time rather than fail at runtime.
- Clean: Crystal has built-in type inference, so most type annotations are unneeded.
- Null Reference Check: Compiler automatically checks for null references in compile time only.
- Macros: We can create and use macros so it's easy to use. your dynamic method definition could be replaced with a compile-time macro in as many lines of code.
- Green Threads: Crystal uses green threads, called fibers, to achieve concurrency. Fibers communicate with each other using channels.
Who and When Crystal language developed?
As per Wikipedia crystal langauge developed by Ary Borenszweig, Juan Wajnerman, Brian Cardiff and some contributors.
Work on Crystal langauge began in 2011, and its first official release was in June 2014.
So we got some basic details about Crystal language so let's proceed with installing it on our local machine.
Installation of Crystal Langauge:
Crystal on Ubuntu System:
Now add the repository to your APT configuration.
sudo apt install libssl-devsudo apt install libxml2-dev sudo apt install libyaml-dev sudo apt install libgmp-dev sudo apt install libreadline-dev
curl -sSL https://dist.crystal-lang.org/apt/setup.sh | sudo bash
Now install Crystal repository.
sudo apt install crystal
And here you are done with your installation is done for Ubuntu system,
Now we will write Hello World program in Crystal Language.
Hello World program in Crystal Language:
- Now Create a file called Hello.cr
- Write the following code in this file.
puts "Hello World"
- Now save it and open the terminal on the same location where file saved
- Run following command:
crystaldemo$ crystal Hello.cr
It should so following output.
$ crystal Hello.cr
And its done you are awesome you have completed your hello world program in crystal language.
Thanks for reading, please comment if you find any issues with it.
Installation & Introduction to Crystal Language Reviewed by Vikas Kad on Sunday, September 09, 2018 Rating: