Upload
kamil-lelonek
View
477
Download
1
Embed Size (px)
Citation preview
CrystalThe Programming Language
@KamilLelonek
Language goalsRuby-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.
Installationsudo 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-docsSource Code: http://bit.ly/crystal-sourceCommunity: http://bit.ly/crystal-community
Examples: • https://github.com/KamilLelonek/crystal-twitter-client • https://github.com/KamilLelonek/crystal-examples
DEMO