Although the Vala project was created back in 2006, it is still little known among both ordinary users and many developers. Few people understand what it is and, most importantly, why it is needed. And among Vala’s Russian-speaking IT community, it’s completely mysterious and articles on this subject are vanishingly small. I decided to correct the current situation a little and make a small digression on this technology.

The current situation in the desktop under Linux
Head over from afar. It so happened that in desktop Linux two technologies (I would say, two different worlds) dominated for a long time - Qt and Gtk. To avoid confusion, I note that Qt is not only a library for building GUIs, but Gtk is just one of many full-stack libraries based on GLib. Accordingly, the desktop is divided between two desktop environments based on these technologies - KDE and Gnome.
For some developers using Qt, everything is pretty smooth and cloudless. They have slim and beautiful APIs, convenient development tools, smart documentation and a large community. In the world of Gtk, things are not so rosy. Initially, development is conducted in the C language, in which, with the help of many abstractions and agreements, GLib is implemented - a full-fledged object model, which has never been in C. The code for applications using GLib looks very peculiar and does not look like what the developers of most popular GUI libraries are used to. In addition, the language itself does not have to develop programs with a graphical interface due to its low level.
As a result, the developer for Gnome has several workarounds. The first is to write on Qt and hope that the application will not look foreign to the rest. The second is to use scripting languages ​​that have Gtk bindings. And there are plenty of them: Python, Ruby, Lua, Lisp, Perl and even PHP. The third is to write in java. All these solutions have obvious advantages - convenience and reduced development time. But there are also disadvantages. First of all, it is the speed of execution, which is noticeably lower in scripting languages, compared to C. The speed of the launch of the program also suffers. Qt is devoid of these shortcomings, but the above-mentioned foreignness, even if substantially leveled in recent years, also makes itself felt.
But the main option, which we have been heavily offered lately, is Mono. In an interview, one of the developers said something like: “You have to be crazy to write programs for Gnome in C when we have Mono”. And it's hard not to agree with him. Mono offers a modern and high-level C # language, a convenient IDE MonoDevelop, an extensive community (which, it should be noted, will mainly be able to help you directly with C #, but not with Gtk application development). Sounds great. However, Mono pulls along all the same problems. The launch and execution speeds are decent enough, but still noticeably lower than those of C. In addition, Mono cannot be a panacea for Gnome, since it is possible to develop only separate software on it, but not the environment itself or its parts in the form of libraries.
This is where the Gnome project came in. Custom software was written on what was acceptable, but not on the original C. Naturally, there were and there are exceptions, but this does not change the fact that there are relatively few developers who are ready to write desktop software in C. And every year their number is clearly not increasing. We needed a simple and elegant solution, and it appeared. As you may have guessed, his name is Vala.
')
What is Vala
First of all, Vala is a project launched in 2006 by only two people - Jürg Billeter and Raffaele Sandrini. It was designed to create convenient, modern tools for Gtk developers and significantly lower the threshold of entry. The project consists of two languages ​​- Vala and Genie. Both, in fact, are one and the same, but have different syntax. Vala is very similar to C # and Java, while Genie has a lot in common with Python and Boo. Since Vala is more popular, then it will be about him.
The concept of Vala is quite simple: the code is written in a convenient high-level language and is translated into the most common C code, which, in turn, is compiled into an executable file or library. The transparency of the broadcast ensures the complete absence of overhead. In other words, when developing on Vala, you don’t pull a single extra library related to Vala. This feature gives another advantage - full binary compatibility. This means that you can write a library in Vala and it can be used from C code (or from any other language if there are bindings). Thus, Vala is suitable for developing not only user software, but also the Gnome environment itself or individual libraries for this project.
Any programming language has a standard library with a set of functions or classes for solving the most obvious tasks. In Vala, this role is performed by a set of standard bindings. The developer has the entire stack of libraries on which Gnome is built. This means that on Vala “out of the box” you can write quite large and complex projects. A complete list of bindings can be found
here . Bindings are vapi-files that explain the translator, how the functions and structures of the library relate to classes, namespaces, methods, etc. You can create your own bindings to existing libraries or to C code.
More about language
As stated above, Vala is very similar to C # and Java. It has real native properties, signals, generics and delegates, abstract classes and interfaces. Multiple inheritance is not, but you can simultaneously inherit from the class and interface. And since the interfaces in Vala can have full-fledged methods, this partly solves the problem (if it ever existed). Also there is no overloading method. But there are default parameters and named constructors. Properties send signals when changing, which is very convenient. Vala supports closures and transparent import of modules. In general, this is a modern and beautiful programming language that has enough expressive means and, at the same time, retains the rigor that is familiar to C # developers. Vala's memory is managed by automatic reference counting, so the developer doesn’t have to think about it all the time. But there is also the possibility of manual control, as in C ++, for example.
Here is an example of the simplest windowing program that, at the touch of a button, displays a message:
using Gtk;
public static int main ( string [] args) {
Gtk.init ( ref args);
Window window = new Window(WindowType.TOPLEVEL);
window.set_size_request(100, 100);
window.destroy.connect(main_quit);
Button button = new Button.with_label( "Push me" );
button.clicked.connect(() => {
MessageDialog msg = new MessageDialog(window, DialogFlags.MODAL,
MessageType.INFO, ButtonsType.OK, "Some message" );
msg.run();
msg.close();
});
window.add(button);
window.show_all();
Gtk.main();
return 0;
}
* This source code was highlighted with Source Code Highlighter .
I think you should not disassemble every line, everything and so it should be clear. More information about the basics of the language can be found in the
official tutorial . To compile this example, you need to enter the following line in the console (provided that the code is saved in the file test.vala):
valac test.vala --pkg gtk+-2.0 -o testTools
The Vala project delivers the translator of the languages ​​Vala and Genie to C. In any popular distribution it is in the official repositories. But, as a rule, these are outdated versions. Therefore, I advise you to look for additional repositories with more recent packages. For Ubuntu, for example, there is a
vala-team .
For Vala, there are several IDEs (if you can call them that). First of all, it is
Val (a) IDE . Able to highlight, directory tree, project file list, autocompletion (so far quite weak), its own build system and support for third-party systems. Nothing needs to be set up, everything is assembled and started by itself, just have time to write the code.
Vala's support is stated in
MonoDevelop and
Anjuta , but personally I got the impression that these environments are more likely to prevent writing code than help.
And finally, what I myself use:
Valencia - plugin for Gedit. He adds autocompletion and symbols for Vala to the standard editor for Gnome. Of course, this is not enough, but at least it does not interfere with writing code, which is already good. A complete list of development tools for Vala can be found at
http://live.gnome.org/Vala in the “IDE Support” section.
But for writing programs of one editor is not enough. Need a build system. In the open source world,
CMake is gaining more and more popularity. This is a very flexible and powerful solution, but ... there is no support for Vala. However, this is a temporary phenomenon and by the next release they promise to correct this unfortunate omission. In the meantime, developers in their projects can use a
special macro that contains the scripts necessary to build Vala programs.
You also can not ignore the
Waf - build system, written in Python and having the original support of Vala. An extremely convenient system that contains everything you need to build and unlimited flexibility, as its scripts are written in Python. But it has one major drawback: not all distributions treat it well. In particular, Debian's maintainers ask developers to switch to another system, since Waf
is scheduled to be removed from the repositories.
More recently, the Vala developers have
announced a very interesting opportunity - the work of Vala in the interpreter mode. It will be possible to write scripts, as in any scripting language, and they will be executed on the fly, without the need to manually assemble them. This greatly simplifies familiarity with the language and makes it more enjoyable, since for your personal experiments you do not need to bother with the assembly and design of the project.
Current state and perspectives of Vala
At the moment, the latest version of Vala is 0.9.3. And the closer to 1.0, the faster the development goes. But all is not well. The roadmap of the project was redrawn several times and, according to one of its editions, Vala 1.0 should have appeared a year and a half ago. Now the
page with the Roadmap has disappeared altogether. Nevertheless, the project is lively and actively developing. Despite the prefinal stages of development, new features are added, including the syntax of the language. This, in turn, brings with it minor inconveniences due to incompatibility and the need to rewrite individual pieces of code when changing versions.
The community at Vala is quite active, albeit small. The main party is the
mailing list , which contains a lot of discussions on any topics related to Vala. There you can also ask a question yourself and most likely get a quick and complete answer. But, in fairness, it is worth noting that not every question has a response. A few months ago, I discovered in Vala an absolutely non-working binding for one of the libraries. I wrote a patch, but got no reaction. Soon, the situation repeated again and I had to add corrected binding directly to my project.
The development of Vala, in my opinion - one of the most important areas for the project Gnome. I do not want to say "salvation", but without steps towards the developers of custom software it will be very difficult to popularize the platform. All the more strange is the dead silence from the side of Gnome about Vala. There is no official movement in this direction from the side of the main patron of this environment - Canonical, the developer of Ubuntu. So far, Vala, as a technology, exists autonomously and its future depends entirely on its own community. So the only way to a happy future is to strengthen and expand this community, which I tried to make this note. Welcome.