Jul 122016
 

Well, you could say it is, but actually it’s a programming language. But nobody heard of it so there’s nothing awesome about it, you might say. WRONG! Here are some of its characteristics that caught my attention:

  • performance on the same level as C, but it’s more of a high-level language
  • compiles Vala code and outputs C code ≡ C cannot do X ⇒ Vala cannot do X
  • syntax ≈ C# (or Java)
  • valac is the name of the compiler; it’s used exactly like gcc
  • some details about data:
    • constants are defined as: const UPPER_CASE
    • you can get the MAX or MIN of a type by using: data_type.MIN or data_type.MAX (int.MIN etc.)
    • strings
      • UTF-8
      • immutable (Java-like)
      • templates: if a = 6 and b = 7 then “$(a*b)” will be evaluated to “42”
      • can be sliced: some_string[start:end]
      • methods like parse or to_string are available
      • in can be used to find a string in another string (instead of strstr in C)
  • delegates: passing functions/methods as objects/variables
  • there is no overloading!
    • for overloading constructors you need to use named constructors:
      • new Button();
      • new Button.with_label(“Click me”);
      • new Button.from_stock(Gtk.STOCK_OK);
    • constructors can be chained by using this
  • signals = events
    • require connect (handlers)
    • are better used with lambda functions (closures)
    • are activated by extern factors
    • always belong to instances of classes
    • every instance of a class derived from GLib.Object has a signal called notify which gets emitted every time a property of its object changes! (properties, later on)
    • examples:
      • instance.signal.connect((t, param_of_signal) => {…});
      • obj.notify.connect((s, p) => { stdout.printf(“Property ‘%s’ has changed! n”, p.name);
        • s = source of the signal
  • properties
    • alice.age++; instead of alice.set_age(alice.get_age() + 1);
    • public int age {get; set; default = 32; }
      • or private set/get, or no set/get at all
      • C#-like
    • keyword construct can be used alongside set/get and whatever is implemented in construct { … } is called after the constructor is called. (starting from the first superclass every class calls its construct block if it exists)
  • contract programming
    • double method_name(int x, double d)
    • requires (x > 0 && x < 10)
    • requires (d >= 0.0 && d <= 1.0)
    • ensures (result >= 0.0 && result <= 10.0)
    • {
      • return d * x;
    • }
    • result = special variable = return value
  • pointers
    • exactly like C
  • chained relational expressions
    • if (0 < a && a < b && b < c) { … }
  • regex allowed!
  • OOP
    • base = super
    • every abstract method of an abstract class must be overridden
    • virtual can be overridden but it is not necessary
    • when implementing interfaces methods should have the same name
    • when implementing multiple interfaces:
      • interface Foo { public abstract int m(); }
      • interface Bar { public abstract string m(); }
      • class Cls : Foo, Bar {
        • public int Foo.m() { return 10; }
        • public string Bar.m() { return “bar”; }
      • }
    • keyword as:
      • (Button) widget ≡ widget as Button
      • less parentheses
    • keyword is:
      • boolean function that tells us if a variable is of a certain type
      • Button b = (widget is Button) ? widget as Button : null;
  • GLib.Object = The Mother of All Classes
    • namespaces are available so using GLib; will allow us to use Object alone

These are just some things I found interesting about Vala. More of it can be found at Valadoc.

As the sixth season of GoT is almost over, all I can say is “Vala(r) morghulis”.


Radu-Dumitru Stochitoiu: Vala? Is it tasty?
Source: Planet Gnome