Vala (programming language)

Vala is an object oriented programming language, which was from 2006 Jürg Billeter and Raffaele Sandrini of people who have studied computer science at ETH Zurich, developed.

Vala 's goal is a modern programming language for development with the object system GObject (which is also the basis of many libraries in the Linux and Unix operating environment Gnome) has to offer, without the need for an additional runtime library (as opposed to mono or Java). In addition, the binary interface is compatible with applications and libraries written in C..

The Vala syntax is very similar to the C # and hence on Java.

Compiler

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

This technique is less suitable because, for example, can not be so efficient intercept exceptions or arithmetic overflows for many programming languages. Since Vala but anyway based directly on C interfaces, this limitation is less significant than in languages ​​such as Eiffel or Haskell.

The advantage is that the C compiler already provides backends for all processor architectures and Vala can benefit from its optimizations. Also a developer can the generated C source code in addition to publish the Vala source code, so that not even the Vala compiler is needed to compile the program. This will be done about the Vala compiler to solve the chicken-and- egg problem, since the Vala compiler itself is written in Vala (self - hosting).

Language

In contrast to Objective- C, with minor exceptions, C , is not an extension of C VALA, since C is not a subset of the VALA syntax. Thus Vala is not a C preprocessor.

The syntax is very similar to C #, and thus Java, but neither Vala is a subset of C # nor vice versa. C # programs so will not compile with Vala, even if we ignore the significant differences in the standard libraries.

Vala is statically typed and strongly and allows inference ( implicit typing ) for local variables. Vala also offers:

  • OOP ( classes, inheritance, virtual methods, abstract classes, interfaces / mixins, type polymorphism )
  • Namespaces
  • Properties (automatic getters and setters )
  • Signals
  • Signal notifications of property changes
  • Foreach loops
  • Lambdas / closures
  • Generic Types
  • Non - nullierbare types
  • Assisted memory management ( automatic reference counting)
  • Deterministic destructors ( allowing RAII )
  • Exception Handling ( Checked exceptions)
  • Asynchronous methods ( coroutines )
  • Preconditions and postconditions (Design by contract )
  • Type information at run time (RTTI )
  • Verbatim strings (strings without interpreting escape sequences, and several lines )
  • Conditional Compilation
  • Static and Dynamic D- Bus support

Memory management

Vala takes the developer from manual memory management. Instead of a garbage collector as in Java or .NET / Mono automatic reference counting is used. Reference counting has the advantage that it is deterministic and real-time capable, but on the other hand must be broken in the case of reference cycles this manually by the developer through the use of a weak reference ( weak reference). Like when in a tree data structure an element holds a reference to its parent element, and this in turn a reference to the child element, ie both refer mutually to each other.

Vala allows optional manual memory management with pointers.

Binary compatibility

In Vala developed libraries are valid C libraries, and can be used directly by C developers because Vala is in contrast to languages ​​such as C , Objective -C and D to the C binary interface ( ABI) compatible.

Libraries

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

Graphical user interfaces can be developed using the Widget toolkit GTK and the surface design tool Glade.

Code Examples

A minimal Hello world program:

Void main () {      print (" Hello world \ n " ); } A more complex variant, which demonstrates some object-oriented features of Vala:

Class Sample: Object {      void run () {          stdout.printf ("Hello world \ 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 = " A simple GTK program ";      window.set_default_size (300, 50);      window.position = WindowPosition.CENTER;      window.destroy.connect ( Gtk.main_quit );        var button = new Button.with_label ( " Click me! ");      button.clicked.connect ( () = > {          Button.label = "Thank you";      });        window.add ( button );      window.show_all ();        Gtk.main ();      return 0; } This program initializes GTK , generated a main window, sets the title, size and position, adds the window a button that connects the signal that is triggered by a mouse click, eventually with an anonymous callback function that changes the caption of the button, and starts the main event loop of GTK .

Bindings

To make a C library with Vala available, no run-time bindings ( wrappers ) are necessary, but only a static description in a so-called vapi file ( Vala API) with annotated Vala syntax that tells the Vala compiler at compile time Vala as method calls to be transformed into C function calls. These files can be generated semi- automatically for GObject -based libraries for non- GObject -based C libraries, they must be written by hand. For a variety of libraries bindings are already available, including for non- GObject -based C libraries such as the multimedia library SDL, OpenGL, etc.

Platforms

Vala's base libraries GLib / GIO and Gee are available on all major platforms, such as various Unix, Linux, Mac OS X, Windows. The only requirements for Vala are the GLib and a C compiler. Vala is therefore not tied to Gnome. If the developer avoids things like platform dependent paths and non- cross-platform libraries and instead uses the abstractions of GLib, he can develop with Vala cross-platform applications. Also, GTK is available for various operating systems. A compiled binary code to Vala program is of course tied to the respective platform, as it then is in the form of native machine code.

Use

Applications that were developed with Vala and have already attained a certain level of recognition, are about the photo management Shotwell, the Twitter client Pino and backup tool Déjà Dup. All three are standard applications of the Linux distribution Fedora since version 13 Also in Ubuntu 10.10 is the pre-installed Shotwell photo management and has replaced F-Spot. Ubuntu's Unity interface was originally developed for netbooks is developed in Vala, as well as DLNA / UPnP Media Server Rygel, which is used among other things to the GNOME project. The Vala compiler itself is an example of a larger, written in Vala command line project.

Others

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

797504
de