Vala for Java Programmers

Vala for Java Programmers

https://live.gnome.org/Vala/ValaForJavaProgrammers

Vala is an object-oriented programming language with a self-hosting compiler that generates C code and uses the GObject system. Vala is syntactically similar to C# and includes useful language features like anonymous functionssignals, properties,genericsassisted memory managementexception handlingtype inference, and foreach statements. It is being developed by Jürg Billeter and Raffaele Sandrini. It aims to bring modern language features to C, with no added runtime needs and with little overhead, by targeting the GObject object system. Rather than being compiled directly to assembler or to another intermediate language, Vala is source-to-source compiled to C which is then compiled with a platform’s standard C compiler, such as gcc.

For memory management, the GObject system provides reference counting. In C a programmer must manually manage adding and removing references, but in Vala managing such reference counts is automated if a programmer uses the language’s built-in reference types rather than plain pointers.

Using functionality from native code libraries requires writing vapi files, defining the library interfacing. Writing these interface definitions is well-documented for C libraries, especially when based on GObject, however C++ libraries are currently not yet supported. Vapi files are provided for a large portion of the GNOME platform, including GTK+.

The following is an example of  Vala’s use of GTK to build a simple GUI:

using Gtk;

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

    var window = new Window();
    window.title = "Hello, World!";
    window.border_width = 10;
    window.window_position = WindowPosition.CENTER;
    window.set_default_size(350, 70);
    window.destroy.connect(Gtk.main_quit);

    var label = new Label("Hello, World!");

    window.add(label);
    window.show_all();

    Gtk.main();
    return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s