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:

<br />
#include &amp;lt;glib.h&amp;gt;<br />
#include &amp;lt;glib-object.h&amp;gt;<br />
#include &amp;lt;stdlib.h&amp;gt;<br />
#include &amp;lt;string.h&amp;gt;</p>
<p>typedef struct _Caller Caller;<br />
#define _g_free0(var) (var = (g_free (var), NULL))</p>
<p>struct _Caller {<br />
	gchar* _name;<br />
};</p>
<p>void caller_free (Caller * self);<br />
static void caller_instance_init (Caller * self);<br />
void caller_call (Caller* self,<br />
                  const gchar* number);<br />
Caller* caller_new (void);<br />
const gchar* caller_get_name (Caller* self);<br />
void caller_set_name (Caller* self,<br />
                      const gchar* value);</p>
<p>void<br />
caller_call (Caller* self,<br />
             const gchar* number)<br />
{<br />
	g_return_if_fail (self != NULL);<br />
	g_return_if_fail (number != NULL);<br />
}</p>
<p>Caller*<br />
caller_new (void)<br />
{<br />
	Caller* self;<br />
	self = g_slice_new0 (Caller);<br />
	caller_instance_init (self);<br />
	return self;<br />
}</p>
<p>const gchar*<br />
caller_get_name (Caller* self)<br />
{<br />
	const gchar* result;<br />
	const gchar* _tmp0_;<br />
	g_return_val_if_fail (self != NULL, NULL);<br />
	_tmp0_ = self-&amp;gt;_name;<br />
	result = _tmp0_;<br />
	return result;<br />
}</p>
<p>void<br />
caller_set_name (Caller* self,<br />
                 const gchar* value)<br />
{<br />
	gchar* _tmp0_;<br />
	g_return_if_fail (self != NULL);<br />
	_tmp0_ = g_strdup (value);<br />
	_g_free0 (self-&amp;gt;_name);<br />
	self-&amp;gt;_name = _tmp0_;<br />
}</p>
<p>static void<br />
caller_instance_init (Caller * self)<br />
{<br />
}</p>
<p>void<br />
caller_free (Caller * self)<br />
{<br />
	_g_free0 (self-&amp;gt;_name);<br />
	g_slice_free (Caller, self);<br />
}<br />

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.

Author: despinosa

Linux and GNOME user, full time, since 2001. Actual maintainer of GXml and contributor to other projects mainly on GObject Introspection support.

One thought on “Vala state: October 2018”

Leave a Reply

Your email address will not be published. Required fields are marked *