What is Vala

    Although the Vala project was created back in 2006, it still remains little known among ordinary users and among 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 at all mysterious and there are vanishingly few articles on this subject. I decided to slightly correct the current situation and take a short excursion on this technology.




    The Current State of Desktop Development under Linux


    Let's go from far away. It so happened that in desktop Linux two technologies have dominated for a long time (I would say two different worlds) - Qt and Gtk. To avoid confusion, I note that Qt is not only a library for building a GUI, and Gtk is just one of many libraries in the full stack, which is 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 slender and beautiful APIs, convenient development tools, great documentation and a large community. In the Gtk world, things are not so rosy. Initially, development is conducted in the C language, in which, with the help of many abstractions and conventions, GLib is implemented - a full-fledged object model that C has never had. The code of applications using GLib looks very peculiar and does not at all resemble what developers of most popular GUI libraries are used to. In addition, the language itself is not conducive to developing 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 in Qt and hope that the application will not look foreign compared to the rest. The second is to use scripting languages ​​that have bindings to Gtk. And there are enough of these: 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 execution speed, which is noticeably lower for scripting languages, compared to C. The launch speed of the program also suffers. Qt is devoid of these shortcomings, but the foreignness mentioned above, albeit substantially leveled in recent years, also makes itself felt.
    But the main option that we have been intensively offered recently is Mono. In an interview, one of the developers said something like this: "You need to be crazy to write programs for Gnome in C, when we have Mono." And it’s hard to disagree with him. Mono offers a modern and high-level C # language, a convenient MonoDevelop IDE, an extensive community (which, it should be noted, will mainly be able to help you with C # issues directly, but not with Gtk application development). That sounds great. However, Mono brings all the same problems. The launch and execution speed is decent enough, but still noticeably lower than that of C. In addition, Mono cannot be a panacea for Gnome, since it is possible to develop only a separate software on it, but not the environment itself or its parts in the form of libraries.
    Here in this situation was the Gnome project. Custom software was written on anything pleasing, but not on the original C. Naturally, there were and are exceptions, but this does not change the fact that there are relatively few developers willing to write desktop software in C. And every year their number is clearly not increasing. A simple and elegant solution was needed, 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 just two people - Jürg Biller and Raffaele Sandrini. It was designed to create convenient, modern tools for Gtk developers and significantly lower the entry threshold. 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 we will talk about it.
    The concept of Vala is quite simple: the code is written in a convenient high-level language and translated into the most ordinary C code, which, in turn, is compiled into an executable file or library. Broadcast transparency ensures a complete lack of overhead. In other words, when developing on Vala you do not drag any extra libraries related to Vala. This feature provides 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 custom 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 problems. In Vala, this role is played by a set of standard bindings. The developer has at his disposal 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 to the translator how library functions and structures relate to classes, namespaces, methods, etc. You can create your own bindings to existing libraries or to C code.

    More about language


    As mentioned above, Vala is very similar to C # and Java. It has real native properties, signals, generics and delegates, abstract classes and interfaces. There is no multiple inheritance, 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 existed at all). Also there is no method overload. 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, it is a modern and beautiful programming language that has enough expressive tools and, at the same time, preserves the severity familiar to C # developers. Vala's memory management is done through automatic reference counting, so the developer does not need to constantly think about it. But there is also the possibility of manual control, as in C ++, for example.
    Here is an example of a simple window program that, at the click 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 parse every line, everything should be clear anyway. More details 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 test.vala file):

    valac test.vala --pkg gtk+-2.0 -o test

    Tools


    The Vala project delivers a translator of the Vala and Genie languages ​​in C. In any popular distribution, it is in the official repositories. But, as a rule, these are obsolete versions. Therefore, I advise you to look for additional repositories with more recent packages. For Ubuntu, for example, there is a vala-team .
    There are several IDEs for Vala (if you can call them that). First of all, it is Val (a) IDE . It can highlight, directory tree, list of project files, auto-completion (so far quite weak), its own build system and support for third-party systems. You do not need to configure anything, everything is assembled and launched by itself, just have time to write the code.
    Vala support announced in MonoDevelop and Anjuta, but personally, I got the impression that these environments are more likely to interfere with writing code than to help.
    And finally, what I use myself: Valencia is a plugin for Gedit. He brings autocompletion and a list of 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 to write programs, one editor is not enough. Need a build system. In the world of Open Source, CMake is gaining more and more popularity.. This is a very flexible and powerful solution, but ... there is no Vala support. However, this is a temporary phenomenon and by the next release they promise to fix this annoying omission. In the meantime, developers in their projects can use a special macro that contains the scripts needed to build programs on Vala.
    Also, you can not ignore Waf - a build system written in Python and having initial support for Vala. An extremely convenient system that contains everything you need for assembly and unlimited flexibility, as its scripts are written in Python. But it has one significant drawback: not all distributions treat it well. In particular, Debian maintainers are asking developers to switch to another system, as Waf is planning to removefrom the repositories.
    More recently, Vala developers have announced a very interesting feature - Vala in 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 status and prospects of Vala


    At the moment, the latest version of Vala is 0.9.3. And the closer to 1.0, the faster the development. But not everything is so good. The roadmap of the project was redrawn several times and, according to one of its editions, Vala 1.0 was supposed to appear another year and a half ago. Now the page with Roadmap has completely disappeared. Nevertheless, the project is lively and actively developing. Despite the pre-final stages of development, new features are added, including in the language syntax. This, in turn, brings with it minor inconvenience due to incompatibility and the need to rewrite individual pieces of code when changing the version.
    The Vala community 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 ask a question yourself and most likely you will get a quick and complete answer. But, in fairness, it is worth noting that not every question finds a response. A few months ago, I found in Vala an absolutely inoperative binding for one of the libraries. I wrote a patch but got no response. Soon, the situation repeated again and I had to add the corrected binding directly to my project.

    The development of Vala, in my opinion, is one of the most important areas for the Gnome project. 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. The stranger the dead silence from Gnome regarding Vala looks all the more strange. There are no official shifts 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 purely on its own community. So the only way to a happy future is to strengthen and expand this community, which I tried to make with this note. Welcome.

    Also popular now: