Seite wählen

NETWAYS Blog

Weekly Snap: OSMC Program, Vala, Foreman & New-look Hardware Shop

30 July – 3 Aug turned over the month with Foremen and Vala tips, new train and hardware shop designs, and much excitement as the OSMC draws near.
Eva counted 79 days down to the OSMC with a presentation by the Icinga Team and an announcement that conference program was live online.
Sebastian then recommended Foreman, a powerful life cycle management tool to complement Puppet, and Gunnar introduced the object-oriented programming language Vala.
Lennart later complained about the newly redesigned ICE 2 trains, while Georg celebrated our new online hardware store design with a special offer.
Karolina ended the week with a lesson in Franconian, for our guests in the lead up to the OSMC in Nuremberg.

Programmieren mit Vala

Vala ist eine objektorienterte Programmiersprache, die auf dem Objekt-Modell von GNOME basiert. Daher ist es besonders leicht, mit ihr z.B. GTK-Programme zu schreiben.
Syntaktisch erinnert Vala sehr an C# und bietet ähnlich starke Features wie sein großes Vorbild: Klassen, Generics, Signale (analog zu Events bei C#), Eigenschaften mit Getter-/Setter-Funktionalität, Reflection und einiges mehr.
Folgendes Beispiel (von der Wikipedia-Seite zu Vala) zeigt, wie ein GUI-basiertes „Hello World“-Programm in Vala aussieht:
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;
}

Kompilieren lässt es sich mit folgendem Befehl (Tipp: Unter Ubuntu muss evtl. das „libgtk2.0-dev“-Paket installiert werden):
valac --pkg=gtk+2.0 -o HelloWorld HelloWorld.vala
Der Vala-Compiler generiert dabei zunächst intern C-Code, der danach mit GCC kompiliert wird. Das Ergebnis ist ein Binary, das – abgesehen von im Programm verwendeten Libraries – neben Glib und GObject keine zusätzlichen Abhängigkeiten hat.
Weitere Vala-Beispielprogramme gibt es z.B. in der offiziellen Dokumentation.