Vala? Is it tasty?

Vala? Is it tasty?

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”,;
        • 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”.


Planning an exciting summer

Planning an exciting summer

Hello guys!

I am a very lucky person for being selected as a Google Summer of Code student for the next 4 months and this blog will be my confidant. Not really a confidant actually, because any of you can see my development. It will just be a reminder for me to keep doing a good work and a crack in the wall for you to see what’s going on.

The project I’m going to be working on is Gnome-Boxes, an application that allows the user to access remote or virtual systems. I’m also lucky to have Zeeshan Ali assigned as my mentor because he doesn’t settle for little. Cheers to that! 😀

Now I just have to work and let you know about the whole process.

To conclude with, Van Gogh said:

I put my heart and my soul into my work and I have lost my mind in the process.

So.. If I put my mind into my work as well I’d lose nothing? I guess I’ll find out soon.

Wish me luck!