Crystal
The Programming Language
@KamilLelonek
Language goals
Ruby-inspired syntax.
Ruby's efficiency for writing code.
C's efficiency for running code.
Compile to efficient native code.
Never have to specify the type of a variable
or method argument.
Have compile-time evaluation and
generation of code, to avoid boilerplate
code.
Installation
sudo apt-get install crystal
sudo yum install crystal
brew tap manastech/crystal && brew install crystal
➜ ~ crystal
Usage: crystal [command] [switches] [program file] [--] [arguments]
Command:
build compile program file
browser open an http server to browse program file
deps install project dependencies
docs generate documentation
eval eval code
hierarchy show type hierarchy
run (default) compile and run program file
spec compile and run specs (in spec directory)
types show type of main variables
--help show this help
--version show version
Run, Build, Compile
➜ ls
hello.cr
➜ crystal hello.cr
Hello World
➜ crystal build hello.cr
➜ crystal ls -l
-rwxr-xr-x hello
-rw-rw-r-- hello.cr
➜ crystal ./hello
Hello World
Execute on the fly:
Compile and run:
Current Status
The project is in pre-alpha stage: language is still
being designed.
The compiler is written in Crystal.
Includes conservative garbage collector, but this
will change in the future.
Crystal vs Ruby
Porting the code from Ruby to Crystal is very easy and most
of the time needs few modifications.
The ported code behaved exactly the same as in Ruby.
The ported code reveals bugs during compilation, which
means that, Crystal helps you have more robust and correct
code.
Limitations
● Incremental compilation is not possible
Because there are no type annotations, the compiler needs to
figure out the type of everything, each time, from scratch.
● It is hard to do a REPL
If code always had type annotations machine code could be
generated and not worry about a variable’s type possibly
changing, or even a type’s instance variables being created or
changed.
● Crystal is not a dynamic language
When it finishes compiling it assigns a type to every variable and
method that were used.
Resources
Documentation: http://bit.ly/crystal-docs
Source Code: http://bit.ly/crystal-source
Community: http://bit.ly/crystal-community
Examples:
• https://github.com/KamilLelonek/crystal-twitter-client
• https://github.com/KamilLelonek/crystal-examples
DEMO

Crystal

  • 1.
  • 2.
    Language goals Ruby-inspired syntax. Ruby'sefficiency for writing code. C's efficiency for running code. Compile to efficient native code. Never have to specify the type of a variable or method argument. Have compile-time evaluation and generation of code, to avoid boilerplate code.
  • 3.
    Installation sudo apt-get installcrystal sudo yum install crystal brew tap manastech/crystal && brew install crystal ➜ ~ crystal Usage: crystal [command] [switches] [program file] [--] [arguments] Command: build compile program file browser open an http server to browse program file deps install project dependencies docs generate documentation eval eval code hierarchy show type hierarchy run (default) compile and run program file spec compile and run specs (in spec directory) types show type of main variables --help show this help --version show version
  • 4.
    Run, Build, Compile ➜ls hello.cr ➜ crystal hello.cr Hello World ➜ crystal build hello.cr ➜ crystal ls -l -rwxr-xr-x hello -rw-rw-r-- hello.cr ➜ crystal ./hello Hello World Execute on the fly: Compile and run:
  • 5.
    Current Status The projectis in pre-alpha stage: language is still being designed. The compiler is written in Crystal. Includes conservative garbage collector, but this will change in the future.
  • 6.
    Crystal vs Ruby Portingthe code from Ruby to Crystal is very easy and most of the time needs few modifications. The ported code behaved exactly the same as in Ruby. The ported code reveals bugs during compilation, which means that, Crystal helps you have more robust and correct code.
  • 7.
    Limitations ● Incremental compilationis not possible Because there are no type annotations, the compiler needs to figure out the type of everything, each time, from scratch. ● It is hard to do a REPL If code always had type annotations machine code could be generated and not worry about a variable’s type possibly changing, or even a type’s instance variables being created or changed. ● Crystal is not a dynamic language When it finishes compiling it assigns a type to every variable and method that were used.
  • 8.
    Resources Documentation: http://bit.ly/crystal-docs Source Code:http://bit.ly/crystal-source Community: http://bit.ly/crystal-community Examples: • https://github.com/KamilLelonek/crystal-twitter-client • https://github.com/KamilLelonek/crystal-examples
  • 9.