Release of the Crystal programming language 1.5

The release of the Crystal 1.5 programming language has been published, the developers of which are trying to combine the convenience of developing in the Ruby language with the high application performance inherent in the C language. The syntax of Crystal is close to, but not completely compatible with, Ruby, despite the fact that some ruby ​​programs run without reworking. The compiler code is written in Crystal and distributed under the Apache 2.0 license.

The language uses static type checking, implemented without the need to explicitly specify the types of variables and method arguments in the code. Crystal programs are compiled into executable files, with macro evaluation and code generation at compile time. In Crystal programs, it is allowed to connect bindings written in C language. Parallelization of code execution is carried out using the "spawn" keyword, which allows you to run a background task in asynchronous mode, without blocking the main thread, in the form of lightweight threads called fibers (Fiber).

The standard library provides a large set of generic functions, including tools for handling CSV, YAML, and JSON, components for building HTTP servers, and WebSocket support. During the development process, it is convenient to use the “crystal play” command, which generates a web interface (localhost:8080 by default) for interactive code execution in the Crystal language.

Major changes:

  • The compiler has added a check for the correspondence of argument names in the implementation of an abstract method and in its definition. If there is a name mismatch, a warning is now issued: abstract class FooAbstract abstract def foo(number : Int32) : Nil end class Foo < FooAbstract def foo(name : Int32) : Nil p name end end 6 | def foo(name : Int32) : Nil ^— Warning: positional parameter 'name' corresponds to parameter 'number' of the overridden method FooAbstract#foo(number : Int32), which has a different name and may affect named argument passing
  • When assigning an argument to an untyped method to the value of a variable, the argument is now constrained to the type of that variable. class Foo @x : Int64 def initialize(x) @x = x # parameter x will be typed @x end end
  • Allows you to add annotations to parameters of methods or macros. def foo(@[MaybeUnused] x); end # OK
  • Added support for using constants as indices and names in tuples. KEY = "s" foo = {s: "String", n: 0} puts foo[KEY].size
  • New File#delete? methods have been added to the File API for deleting files and directories. and Dir#delete?, which return false if the file or directory is missing.
  • The protection of the File.tempfile method has been strengthened, which now does not allow null characters in the lines that form the file name.
  • Added environment variable NO_COLOR, which disables color highlighting in compiler and interpreter output.
  • Work in interpreter mode has been significantly improved.

Source: opennet.ru

Add a comment