Explore Crystal - twin brother of ruby " ego

Explore Crystal - twin brother of ruby

Meet Crystal is a compiled programming language, like Ruby Potter, who came to the 1.0 release. Despite the fact that this technology has already been in circulation for several years there were several earlier releases), the latest version is the first, which was found to be Mature. Moreover, the creators want their language was with any version 1.x is stable and working back – so that there are no changes that can happen, and can mess up existing code. Those who will use future versions of Crystala can also be confident that their current code will be easily made up by production in subsequent versions. The developers do not plan to change or throw away any libraries and standard library will be improved taking into account backward compatibility.

Crystal 1.0 open source and located on Github. Also see the installation instructions which you can find here.

And now we will try to convey to You the main features of this language. Let’s go!!!

The syntax and type system

As we can read on page Crystala, it the syntax is very much based on Ruby syntax Potter – easy so there writes and reads. Moreover, as the creators of a new language, an additional advantage is the fact that the developers of Ruby Potter will have a very low entry threshold.

Here is an example code written in Crystal:

# A very basic HTTP server
require "http/server"

server = HTTP::Server.new do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world, got #{context.request.path}!"

puts "Listening on"

If we are talking about the type system, Crystal uses static type checking. This means that there is a high probability that errors will have been caught by the compiler and not get into the program when it is started.

As we can read on the page language, the Crystal also has a built-in inferencję types – it allows you, the developers, to maintain order in your code and eliminates the need for type annotations.

Look at the following example:

def shout(x)
# Notice that both Int32 and String respond_to `to_s`

foo = ENV["FOO"]? || 10

typeof(foo) # => (Int32 | String)
typeof(shout(foo)) # => String

Read more about the type system Crystala you can find here.

Null reference checking and macros

Types in the Crystal cannot be null. Variables that can be nullami were presented as European style with nullem. The compiler will find, so automatically all the empty references at compile time.

The new language also has a fairly powerful macro system, which allows, in particular, on the creation of templates and audit act. With it, you can also launch external programs.

Here’s an example from page to Crystal:

class Object
def has_instance_var?(name) : Bool
{{ @type.instance_vars.map &.name.stringify }}.includes? name

person = Person.new "John", 30
person.has_instance_var?("name") #=> true
person.has_instance_var?("birthday") #=> false

Concurrency and dependency

According to the developers, Crystal provides us with threads that we call fiber, they help to obtain parallelism. The fibers are connected to each other by means of channels (as well as in His and Clojure), and you should not access the shared memory.

Speaking of which, it should also be noted that performance Crystala in many standardized tests at the same level It.

If we are talking about dependencies, libraries Crystal packaged in what we call the fragments (shards.). They are distributed with Git, and there is no need for a Central repository. Built-in commands, in turn, define the dependency using YAML. They can be easily removed from their storage.

Here is an example code:

name: my-project
version: 0.1
license: MIT

crystal: 0.21.0

github: crystal-lang/crystal-mysql
version: ~> 0.3.1


On the one hand, it seems that the Crystal is an interesting proposition, especially for people familiar with ruby. With another hard, maybe he can break through into the mainstream and gain significant market share.

In the first place because currently, about strength, a programming language determines to a large extent the ecosystem around it.

In the case of Crystala you can’t talk about the support of large organizations, but rather is a relatively small group of enthusiasts. At this stage, the ecosystem is in its infancy, when we compare it to a more developed competition. Therefore, before Crystalem a heavy task.

Go to our cases Get a free quote