The syntax of Vala is similar to C#, modified to better fit the GObject type system. Vala supports modern language features as the following:

Keywords

Flow Control

Declarations

Resource Control

Literals

Operators

Differences

Arrays

Local arrays can be initialized like this:

var floats = new float[] { 1, 2, 3 };

or without type inference:

float[] floats = { 1, 2, 3 };

In class context currently the only supported syntax for array initialization is this:

class ValaSyntax {
    /* public */ const float[] FLOATS = { 1, 2, 3 };
}

Interfaces

The GObject type system allows interfaces to have non-virtual methods. Therefore interface methods have to be marked as "public abstract" in Vala:

interface ValaSyntax {
    public abstract void do_it()
}

This is different from C# where you write:

interface ValaSyntax {
    void do_it()
}

Object Construction

As Vala uses GObject as type system, its object construction mechanisms are quite different from those found in other object oriented languages. There's also an example which shows the properties' initialisation steps.

Prerequisites

The GObject type system allows classes like Gtk.Widget to be prerequisites of interfaces. As automatic inheritance from Gtk.Widget by implementing an interface would be confusing, prerequisites are not automatically inherited in Vala:

public interface Foo : GLib.Object {}
public interface Bar : Foo {}
public class FooBar : GLib.Object, Foo, Bar {}

In C# or Java specifying just Bar would have been sufficient:

public class FooBar : Bar {}

Properties

Vala has support for construction-only properties:

string filename {
    get { return _filename; }
    construct { _filename = value; }
}

Namespaces

Namespaces can contain methods:

namespace Gtk {
    void main();
}

A namespace can be specified at the class definition:

class Namespace.ClassName {
    void main();
}

Vala/Syntax (last edited 2009-01-19 12:29:58 by Frederik)