Like Ruby, but with types and stuff
👋🏼
History / Basic intro
First commit Sep 2012
History / Basic intro
We love Ruby's efficiency for writing code.
We love C's efficiency for running code.
We want the best of both worlds.
We want the compiler to understand what we mean without having to specify types everywhere.
We want full OOP.
Oh, and we don't want to write C code to make the code run faster.
History / Basic intro
Valid Ruby and Crystal!
History / Basic intro
4X
21X
History / Basic intro
Technical background
Compilers are hard
Technical background
The LLVM Compiler Infrastructure
https://en.wikipedia.org/wiki/LLVM#/media/File:LLVM_Logo.svg
Technical background
Does (most of) the hard work!
Technical background
Hello World in LLVM IR
Technical background
It's easy to generate IR
https://www.slideshare.net/crystallanguage/crystal-internals-part-1-70673255
Technical background
Syntax / Features
Syntax / Features
Basic Types
| Literal | Value |
|---|---|
| Nil | nil |
| Bool | true / false |
| Int32, Int64, Integer | 1, -2, 19_i64, 8_u8 |
| Float64, Float | 1.0, 1.0_f32 |
| Char | 'a' |
| String | "a" |
| Symbol | :a |
| Array | [1,2], [] of Int32 |
| Hash | {"a":1},{} of Symbol => Int32 |
| Tuple | {1,"a",:b} |
Syntax / Features
Arrays
Type inference! Union types!
Syntax / Features
Arrays
Quality error messages
Syntax / Features
Syntax / Features
Syntax / Features
Procs
Syntax / Features
Requiring code
GEM_HOME
Just 'src' and 'lib' matter in the project root
Syntax / Features
Classes
Syntax / Features
Classes
Syntax / Features
Classes
Syntax / Features
Classes
Syntax / Features
Type aliases
Syntax / Features
Generics
Syntax / Features
Method overloading
Syntax / Features
Type fencing
Syntax / Features
Return types
Syntax / Features
Visibility
Syntax / Features
Syntax / Features
C bindings
Syntax / Features
Finalizers
Syntax / Features
Structs
Therefore structs are mostly useful for immutable data types and/or stateless wrappers of other types, usually for performance reasons to avoid lots of small memory allocations when passing small copies might be more efficient
From the docs:
Syntax / Features
Enums
Syntax / Features
Macros
Run at compile-time
No runtime dispatch
Syntax / Features
Monkey-patching
Syntax / Features
Monkey-patching
Syntax / Features
Shards
Syntax / Features
Shards
Syntax / Features
https://shards.info
https://shardbox.org
https://shards.info
https://shards.info
No central repo!
Syntax / Features
Channels
Syntax / Features
crystal play
Web based REPL
Syntax / Features
crystal tool formatter
Built-in code formatter!
Syntax / Features
Written in Crystal!
Syntax / Features
Written in Crystal!
Syntax / Features
Syntax / Features
Syntax / Features
Lucky 0.18
Rails 6.0.2
100X!
Syntax / Features
https://github.com/kostya/crystal-benchmarks-game
Possibilities
Fast, type-checked web apps
Possibilities
Fast, type-checked web apps
Possibilities
New kinds of projects
https://github.com/ffwff/lilith
Possibilities
New kinds of projects
Possibilities
Possibilities
The bad