Designed by Ary Borenszweig Implementation language Crystal | Typing discipline static | |
Paradigm Multi-paradigm: Object-oriented Developer Manas Technology Solutions Preview release 0.20.3 / December 23, 2016; 2 months ago (2016-12-23) |
Crystal is a general-purpose, object-oriented programming language designed and developed by Ary Borenszweig and Juan Wajnerman and over one-hundred listed contributors. Crystal is developed as open source software (under the Apache License, Version 2.0) with syntax inspired by Ruby. The language is statically type-checked but does not require that the type of variables or method arguments be specified. This is the result of advanced global type inference. The language is in an active development phase.
Contents
History
Work on the language began in June 2011, with the purpose of creating a language which had the elegance and productivity of Ruby and the speed, efficiency and type safety of a compiled language. Initially called Joy, it was quickly renamed to Crystal.
In November 2013, the Crystal compiler (previously written in Ruby) became self-hosting. The first official version was released in June 2014. In July 2016 Crystal was added to the TIOBE Index.
Description
Although resembling the Ruby programming language in syntax, Crystal compiles to much more efficient native code using an LLVM backend, at the cost of disallowing the dynamic aspects of Ruby. However, the advanced global type inference used by the Crystal compiler, combined with the usage of union types, give Crystal the feel of a higher-level scripting language than many other comparable programming languages. The language has automated garbage collection and currently offers a Boehm collector. Crystal possesses a macro system and supports generics and method and operator overloading. Crystal's concurrency model is inspired by communicating sequential processes (CSP), and implements light-weight fibers and channels (for communicating between fibers) inspired by the Go programming language.
Hello World
This is the simplest way to write the Hello World program in Crystal:
Or using an object-oriented programming style:
Type inference and union types
The following code defines an array containing different types with no usable common ancestor. Crystal automatically creates a union type out of the types of the individual items.
Concurrency
Channels can be used to communicate between fibers, which are initiated using the 'spawn' keyword.