Ruby Programming language
23-02-2022, 14:04
Crystal
Programming language
Wikipedia
An object-oriented general-purpose programming language designed and developed by Arie Borenzweig, Juan Weinerman and Brian Cardiff. Developed by a community of over 300 developers. It has a Ruby-like syntax, but, unlike Ruby, it is compiled and statically typed. Read more
Year of release: 2014
Platform: X64
Website: crystal-lang.org
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. The other day, version 1.0 of another language, Crystal, was released.
Its creators claim that the language is simple, like Ruby, and fast, like C. It cannot be called new, since it has been developed since 2011, precisely as an alternative to Ruby. The authors of the project state 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 about the project before, here is a brief description of it. Crystal is a high-level object-oriented programming language. Its syntax is very similar to Ruby syntax, but differs from its competitor in that it is compiled into 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 at once - they make it possible to write fast applications, and provide a low threshold for entering development.
What is special about Crystal?
First of all, it is a language with static typing. This is 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 problem of automatic memory management by using a "conservative" garbage collector Boehm GC. The language supports both macros and generics, plus it is able to work with overloading of methods and operators.
The advantage of Crystal is that, like Ruby, it offers an OS-independent implementation of multithreading. Lightweight threads in Crystal are called "fibers". Threads, as in the Go and Clojure languages, can interact with each other through channels, without having to resort to using shared memory or locks.
Crystal implements an interface for calling functions from C libraries. At the same time, the interaction syntax is simple - accordingly, using Crystal, you can create wrapper libraries, without having to write code from scratch.
The standard language library provides a wide range of typical functions, 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 1.0 release?
There are not many changes, but they can be called critical.
Firstly, in tuples, it is now possible to access elements of different types by index. The compiler is able to determine which type each of them belongs to.
Secondly, the standard library has been cleared of outdated and not recommended definitions. These are, for example, methods:
HTTP::Request,
HTTP::WebSocket,
HTTP::LogHandler,
URI#full_path,
Time::Span#duration.
Thirdly, the developers have changed the principle of cookie processing. In the final release, 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 OS and processors with ARM architecture.
There are also a few less significant changes:
In string and character literals, the use of surrogate abbreviations in Unicode escape sequences, such as "\uD834", is prohibited. To encode arbitrary values, use the notation "\x".
The default rounding method has been 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 Number#round, which allows you to select the rounding method. Among the available methods: TIES_EVEN, TIES_AWAY, TO_ZERO, TO_POSITIVE, TO_NEGATIVE.
Enumerable#flat_map and Iterator#flat_map work with elements of mixed types in collections.
When serializing Enum sequences, a representation in the form of strings with underscores is now used.
The types defined in the XML module are translated from using struct to class.
Well, a little 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 already on Crystal.
The official version of the language was released in 2014. Over time, Crystal has become an open source project that is distributed under the terms of the Apache License 2.0.
The development is being carried out with the money of 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 it can already be used in your projects.
23-02-2022, 14:04
23-02-2022, 12:41
23-02-2022, 13:19
5 comments
Information
Users of Visitor are not allowed to comment this publication.