Released the Crystal programming language version 1.0: advantages, features and a little history

There are a lot of programming languages in the world — about 8 thousand, if you take into account everything that can be considered a programming language, including all sorts of comic and theoretical projects. Recently released version 1.0 of another language — Crystal. Its creators claim that the language is as simple as Ruby and as fast as C. It can not be called new, since it has been developed since 2011 as an alternative to Ruby. The authors of the project claim that the language is now ready for use under normal conditions and is stable.

What kind of language is this?

If you haven't heard of this project yet, here's a brief description. Crystal is a high-level object-oriented programming language. Its syntax is very similar to that of Ruby, but differs from its competitor in that it compiles to machine code via LLVM. According to developers and third-party companies that have already tested the language, the performance of applications written in Crystal is comparable to applications in C. The latter is considered more difficult to master than Ruby. Thus, the creators of Crystal kill two birds with one stone-they make it possible to write fast applications and provide a low threshold for entering development.

What's so special about the Crystal?

First of all, it is a language with static typing. That's how it differs from Ruby. In practice, this means that variable type mismatch errors are detected by the compiler already at the stage of processing the source code into machine code, and not during its execution by the interpreter. At the same time, the language does not need to specify specific types of variables or method arguments. The fact is that the compiler outputs them independently, using a specialized mechanism. The developers have provided for the task of automatic memory management using a "conservative" garbage collector (garbage collector) Boehm GC. The language supports both macros and generics, plus it can work with overloading methods and operators. The advantage of Crystal is that, like Ruby, it offers an operating system-independent implementation of multithreading. The light filaments in the crystal are called "fibers". Threads, as in the Go and Clojure languages, can communicate with each other over channels without resorting to using shared memory or locking. Crystal implements an interface for calling functions from C libraries. At the same time, the interaction syntax is simple — accordingly, you can use Crystal to create wrapper libraries without having to write code from scratch. The Standard Language library provides a wide range of standard features, including tools for processing CSV, YAML, and JSON, components for creating HTTP servers, and WebSocket support. During the development process, it is proposed to use the "crystal play" command, which forms a web interface (by default, localhost: 8080) for interactive code execution in the Crystal language.

What has changed with the release of version 1.0?

There are not many changes, but they can be called critical. First, in tuples, you can now access elements of various types by index. The compiler is able to determine which type each of them belongs to. Second, the standard library has been purged of outdated and deprecated definitions. These are, for example, methods:
  • HTTP::Request,
  • HTTP::WebSocket,
  • HTTP::LogHandler,
  • URI#full_path,
  • Time::Span#duration.
Third, the developers have changed the way they handle cookies. In the final version, the HTTP method::Cookies.from_headers is divided into separate server and client versions. Accordingly, the values and file names are not encoded / decoded for security reasons. There are also changes that have already been made, but are not yet officially supported. These include multithreading, which is activated in an environment with a multi-core processor using the-Dpreview_mt flag, support for Windows and ARM processors.
There are also a few less significant changes:
  • String and character literals do not allow the use of surrogate abbreviations in Unicode escape sequences, such as"\uD834". To encode arbitrary values, use the notation "\x".
  • The default rounding method is changed to TIES_EVEN ("banker rounding", to the nearest integer, and for borderline situations, to the nearest even number). The RoundingMode parameter has been added to the#round number, which allows you to select the rounding method. Among the available methods: TIES_EVEN, TIES_AWAY, TO_ZERO, TO_POSITIVE, TO_NEGATIVE.
  • The#flat_map enumerator and the#flat_map iterator work with elements of mixed types in collections.
  • When serializing enumeration sequences, the representation is now used as strings with underscores.
  • The types defined in the XML module are translated from using struct to class.

Well, a bit of history

As mentioned above, the development of the language began 10 years ago. The authors of the project are the founders of the Argentine company Manas Technology Solutions. Initially, the language was called Joy, and the compiler for it was created in Ruby. A little later, in 2013, it was rewritten to Crystal. The official version of the language was released in 2014. Over time, Crystal became an open source project that is distributed under the terms of the Apache 2.0 license. The development is being funded by investors, including Nikola, which has been developing electric vehicles for many years, but has not yet presented a working prototype. But the language itself is quite working, and you can already use it in your projects.
Popular articles