Vala (programming language)

from Wikipedia, the free encyclopedia
Vala
Paradigms : object-oriented
Publishing year: 2006
Developer: Rico Tzschichholz (main), Jürg Billeter, Raffaele Sandrini
Current  version 0.46.1   (September 16, 2019)
Typing : static , strong
Influenced by: Boo , C , C ++ , C # , D , Java
Operating system : all with ANSI-C compiler, since Vala generates C code
License : LGPL 2.1+
wiki.gnome.org/Projects/Vala

Vala is an object-oriented programming language that was developed in 2006 by Jürg Billeter and Raffaele Sandrini, who studied computer science at the ETH Zurich .

Vala aims to provide a modern programming language for development with the GObject object system (which is the foundation of all GTK + / Gnome applications) without the need for an additional runtime library (in contrast to Mono or Java ). The binary interface is also compatible with applications and libraries written in C.

The Vala syntax is very similar to that of C # and thus also of Java .

Compiler

The Vala compiler translates the Vala source code into C source code and lets the C compiler do the rest.

This technique is less suitable for many programming languages. B. Not efficiently catching exceptions or arithmetic overflows. Since Vala is based directly on C interfaces anyway, this restriction is less important than with languages ​​like Eiffel or Haskell .

The advantage is that the C compiler already has backends for all processor architectures and Vala can benefit from its optimizations. A developer can also publish the generated C source texts in addition to the Vala source texts, so that not even the Vala compiler is required to compile the program. This is done with the Vala compiler, for example, to solve the chicken and egg problem , since the Vala compiler itself is written in Vala (self-hosting) .

language

In contrast to Objective-C , and with few exceptions C ++ , Vala is not an extension of C, since C is not a subset of the Vala syntax. Thus Vala is not a C preprocessor either .

The syntax is strongly based on C # and thus also Java , but Vala is neither a subset of C # nor vice versa. So C # programs cannot be compiled with Vala, even if one ignores the considerable differences between the standard libraries.

Vala is static and strongly typed and allows type inference (implicit typing) for local variables. Among other things, Vala offers:

Memory management

Vala relieves the developer of manual memory management. Instead of a garbage collector as in Java or .NET / Mono , automatic reference counting is used. Reference counting has the advantage of being deterministic and real-time capability is, but must on the other hand, in the case of reference cycles manually by the developer by using a weak reference (weak reference) are broken; for example when an element in a tree data structure holds a reference to its parent element and this in turn has a reference to the child element, i.e. both refer to each other.

Vala also allows manual memory management with pointers as an option .

Libraries

Binary compatibility

Libraries developed in Vala are valid C libraries and can be used directly by C developers, since Vala, in contrast to languages ​​like C ++ and D, is compatible with the C binary interface (ABI).

Standard library

As a standard library, Vala uses the GLib with its sub-modules GIO, GObject , GModule, which is available for most systems and offers things like platform-independent threading , input / output , file management, network sockets , plug-ins , regular expressions and much more . There is also a library called Gee , written in Vala, that provides generic Collection / Container classes.

Graphical user interfaces can be developed with the GTK + GUI toolkit and the Glade surface design tool .

Bindings

In order to make a C library usable with Vala, no runtime bindings ( wrappers ) are necessary, just a static description in a so-called vapi file (Vala API ) with annotated Vala syntax, which the Vala compiler tells at compile time how Vala method calls are to be transformed into C function calls . These files can be generated semi-automatically for GObject-based libraries, for C-libraries not based on GObject they have to be written by hand. Bindings are already available for a large number of libraries, including for C libraries that are not based on GObject, such as the SDL , OpenGL etc.

Platforms

Vala's basic libraries GLib / GIO and Gee are available on all common platforms, such as various Unixes , Linux , macOS and Windows . The only requirements for Vala are the GLib and a C compiler. So Vala is not tied to gnomes . If the developer avoids things like platform-dependent path information and non-cross-platform libraries and instead uses the abstractions of the GLib, he can develop cross-platform applications with Vala. GTK + is also available for the various operating systems. A Vala program compiled into binary code is tied to the respective platform, as it is then available in the form of native machine code .

distribution

Applications that were developed with Vala and have already achieved a certain level of popularity include the Shotwell photo management system , the Twitter client Pino and the backup tool Déjà-Dup. All three are standard applications of the Linux distribution Fedora from version 13. Shotwell is also the pre-installed photo management in Ubuntu 10.10 and has replaced F-Spot . Ubuntu's Unity interface, originally developed for netbooks, is being developed in Vala, as is the DLNA / UPnP media server Rygel, which is used in the GNOME project, among others. The Vala compiler itself is an example of a larger command line project written in Vala.

In the TIOBE index as of April 2018, Vala is listed between 51st and 100th place.

However, some GNOME developers refer to Vala as a dead language and advise against choosing Vala as the programming language for new applications.

Code samples

A minimal hello world program :

void main() {
    print("Hallo Welt!\n");
}

A more complex variant that demonstrates some object-oriented properties of Vala:

class Sample: Object {
    void run() {
        stdout.printf("Hallo Welt!\n");
    }

    static void main(string[] args) {
        var sample = new Sample();
        sample.run();
    }
}

This code example demonstrates a simple GTK + program:

using Gtk;

int main (string[] args) {
    Gtk.init(ref args);

    var window = new Window();
    window.title = "Ein einfaches GTK+ Programm";
    window.set_default_size(300, 50);
    window.window_position = WindowPosition.CENTER;
    window.destroy.connect(Gtk.main_quit);

    var button = new Button.with_label("Klick mich!");
    button.clicked.connect(() => {
        button.label = "Dankeschön";
    });

    window.add(button);
    window.show_all();

    Gtk.main();
    return 0;
}

This program initializes GTK +, creates a main window, sets its title, size and position, adds a button to the window and connects its signal , which is triggered by a mouse click, with an anonymous callback function , which changes the label of the button, and finally starts the main event loop of GTK +.

Others

Vala has a sister language called Genie , which also uses the Vala compiler infrastructure and has a Python- like syntax with static typing.

literature

  • Christian Meyer: Vala - language and compiler for the GObject type system . GObject without a headache. In: Linux Magazine} . tape November 6 , 2007 ( online [accessed August 13, 2019]).

Web links

Individual evidence

  1. gitlab.gnome.org . (accessed on September 22, 2019).
  2. https://www.tiobe.com/tiobe-index/
  3. Emanuelle Bassi: halting problem: On Vala. In: bassi.io. February 13, 2017, accessed February 13, 2017 .
  4. https://www.phoronix.com/scan.php?page=news_item&px=GNOME-Vala-Bassi