9
Crystal The Programming Language @KamilLelonek

Crystal

Embed Size (px)

Citation preview

Page 1: Crystal

CrystalThe Programming Language

@KamilLelonek

Page 2: Crystal

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.

Page 3: Crystal

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

Page 4: Crystal

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:

Page 5: Crystal

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.

Page 6: Crystal

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.

Page 7: Crystal

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.

Page 8: Crystal

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

Page 9: Crystal

DEMO