Vala state: October 2018

Maintainability

While I think maintainability could be improved, adding to history commits from contributions, apart from the ones coming from current Maintainer. Actually, there are some lot of commits not in history coming from authors outside current ones. Hope with new GitLab GNOME’s instance, this will reflect the correct situation.

Behind scenes, Vala has to improve its code base to adapt to new requirements like to develop a descent Vala Language Server and more IEDs supporting Vala. At least for me, even GEdit is productive enough to produce software in Vala, because the language itself; write a Class, an Interface and implement interfaces, is 10 times faster in Vala than in C.

Vala has received lot of improvements in last development cycles, like a new POSIX profile, ABI stability, C Warnings improvements and many other, to be reported in a different article.

Look at Vala’s repository history, you will see more “feature” commits than “bindings” ones, contrary to the situation reported by Emmanuel, while should be a good idea to produce a graphic on this, but resent improvements could tell by them self the situation has been improved in recent release cycles.

Lets look at repository’s chart. It reports 2000 commits in the last 3 months, 1.1 average per day, from 101 contributions as for October 19, 2018. Me at 10 commits from the last year, so I’m far to be a core contributor, but push ABI stability to be a reality. My main contributions are to communicate Vala advances and status.

Vala as a language

Vala has its roots as a GObject oriented language. Currently for C too, because it can produce C code without dependent on GLib/GObject.

Program a C code base using an Object Oriented Programming is easy on Vala, even if the C output are GObject classes or not. You can produce Compact Classes, as forĀ  Vala’s Manual:

Compact classes, so called because they use less memory per instance, are the least featured of all class types. They are not registered with the GType system and do not support reference counting, virtual methods, or private fields. They do support unmanaged properties. Such classes are very fast to instantiate but not massively useful except when dealing with existing libraries. They are declared using the Compact attribute on the class

In C a compact class is a simple struct, its fields can have accessors, so your users just call a get/set method to access it and run additional code when is done. Following code:

[vala]
[Compact]
class Caller {
  public string _name;
  public string name {
    get {
      return _name;
    }
    set {
      _name = value;
    }
  }
  public void call (string number) {}
}
[/vala]

Is translated to:

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

typedef struct _Caller Caller;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _Caller {
	gchar* _name;
};



void caller_free (Caller * self);
static void caller_instance_init (Caller * self);
void caller_call (Caller* self,
                  const gchar* number);
Caller* caller_new (void);
const gchar* caller_get_name (Caller* self);
void caller_set_name (Caller* self,
                      const gchar* value);


void
caller_call (Caller* self,
             const gchar* number)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (number != NULL);
}


Caller*
caller_new (void)
{
	Caller* self;
	self = g_slice_new0 (Caller);
	caller_instance_init (self);
	return self;
}


const gchar*
caller_get_name (Caller* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->_name;
	result = _tmp0_;
	return result;
}


void
caller_set_name (Caller* self,
                 const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->_name);
	self->_name = _tmp0_;
}


static void
caller_instance_init (Caller * self)
{
}


void
caller_free (Caller * self)
{
	_g_free0 (self->_name);
	g_slice_free (Caller, self);
}

Could you find some improvements in C code generation?

As you can see, Vala generates code to create your struct, access your fields while run costume code, to free your struct and initialize it. Your C users will have a clean and easy API to use, as you expect, your struct.

If you use Vala to access your C struct, also written in Vala, it will create and free correctly automatically.

So,

Less code, more features.

Vala Pushing up Complex projects

GObject/GInterface are a powerfull tool, but is really hard to use in C if you have to write and implement a complex hierarchy of classes and interfaces. W3C DOM4, is a clear example of it; sure is possible implement in C, but is hundred times easy to implement and maintain in Vala.

GXml and GSVG are an example on how complex a hierarchy can be, and how they have been implemented in a short time.

GXml’s GomElement hierarchy just shows all interfaces it should implement to be DOM4’s Element.

Have you tried to write lot of fragmented featured interfaces in C and implement all of them in a single GObject class?

W3C SVG 1.1 specification have lot of interfaces to write and implement to have a fully compliant object’s class.

Implement GSVG over Vala, makes SVG 1.1 possible in a short time; but don’t stop here, because maintain this complex hierarchy, like move an object from final to derivable one, or move methods from a final to parent class, including its interface implementation, is hundred times easy to do in Vala than in plain C/GObject.

Vala allows: Complex Interface hierarchy implementation easy

While GSVG implementation is not completed, Vala is the right tool to use on this kind of projects.

Vala libraries are Introspectable and usable in other languages

Yes, C GObject classes are introspectable, but lot of annotations are required to produce GIR/TYPELIB, usable in Python or JavaScript.

Vala code produce Introspection Annotations as you write. Produce GIR XML file format is a matter to use --gir switch. Errors and warnings in Vala are focused to make your classes introspectable consistent; for example, you can’t return NULL in Non NULL declared methods.

Vala Scripting?

Vala Language Server

I’m working with a library called GNOME Vala Language Server (GVls), as a proof of concept for a server that will serve autocompletion, syntax highlighting and that kind of stuff, but found something interesting by accident.

I’ve added an interface called Client, may is not it final name, but it allows to locale a symbol in a already parsed file, along with some goodness from other interfaces and implementations, I’ll talk about in another article.

The Accident

While trying to create a in-line parser to detect if the actual word is an object or any other kind of symbol to, in the near future, propose a list of properties and methods or a list of method’s parameters, by accident Client now can parse in-line Vala code, so you push text to this Client object and a Server (the object that parse and handle Symbol collection), parseĀ  it and just add new Symbols to its collection, without any effort or parse errors for incomplete code!!!!

So now if you push the folowing text:

class Push {\n

Server now find a Push symbol representing a new Vala class. Inserting a medhod:

public void callme () {

You can find in the Server a new symbol for Push.callme method. Just no error, even if the code is not completed yet.

Vala Scripting?

Well not for now. But with this work the doors are opening. This include Genie, because it has more script suitable syntax than Vala. Any way, leave to the time and some others’ help of course.

GDA 6.0 progress

GDA project has released 5.2.5 and tagged 5.2.6, with some improvements, but the real work is on master.

Master is targeting 6.0, a new ABI/API release, providing better GObject Introspection support and code modernization.

A new Meson build system is on the way to replace Autotools. Meson helped to implement, fix and test all changes in less time. Like on multi-threading, where is more easy to produce multiple parallel tests, helping to expose issues to fix. Master have big improvement on that matter.

API is almost the same with minor changes, so port to new one should be easy. Major API breaks will happen on 7.0 development cycle.

GDA have really old code, modernization of public API has been the priority; but, some parts are very sensitive to the change, so they may never will change or will wait to 7.0 cycle.

GDA’s GTK+ widgets, has been ported to avoid Deprecated API by recent 3.x releases. No heavy changes here, apart of the code modernization. GDA’s Control Center and Browser, has been fixed, so they are back from the dead. There are other, more modern applications out there like Sequeler, so in the short term may this tools old will be removed, unless there are interest by users.

My experiment on mix Vala code with C source in GDA should wait, but I found it functional, just some improvements in Vala code generation adding C source documentation are required.

Beyond 6.0, there are interest in improve implementation of new database Providers. At first, I’ve tried to make more deep changes in API to make room for a new providers platform, but the way current one and connection objects are tied each other makes that hard, so I decided to wait until 7.0 cycle starts.

In parallel, I’m developing a new Vala library called libvda, to experiment with a new platform for providers. It is exposing a set of interfaces, making more easy to have new providers; load them thought libpeas is planned.

Currently libvda has objects to connect to PostgreSQL and SQLite, using a common GDA provider object; add more existing GDA’s providers is a matter of a really few lines of code, thanks to Vala.

Because GDA has a very slow mechanism to generate Meta information about data base’s objects, I plan to expose meta queries directly, so they can be used faster. libvda, expose interfaces to access meta information using a GObject API, but there is a new DDL module in GDA for meta information, but that is another history for a different article.

Design and implement interfaces an objects in Vala is about 8 to 10 times faster, considering API changes in the development process. This is why I can expend time on libvda, to check out how could be on GDA and why I’m considering to mix Vala source code with C one.