Vala applications on Embedded Linux: maybe a clever choice [part 1]

Felipe LavrattiDecember 19, 2016

Vala is a sexy, open source, high level programming language that appeared in 2006, it counts with a modern typing system, is object oriented, compiled and statically typed, it has a almost identical syntax to C# and is maintained by GNOME. The language was created as a power abstraction of the GLib and GTK libraries, two considerably lightweight and powerful libraries written in C, and it is used in projects such as GNOME Clocks, Shotwell, GXml and Elementary OS.

namespace LedDancingDemo
{
    int main (string[] args)
    {
        var loop = new MainLoop();

        LedState[] states = new LedState[] {
            LedState(true , true , true ),
            LedState(false, true , true ),
            LedState(true , false, true ),
            LedState(true , true , false),
            LedState(true , true , true ),
            LedState(false, false, false),
            LedState(true , true , true ),
            LedState(false, false, false),
            LedState(true , true , true ),
            LedState(false, false, false),
            LedState(true , true , true ),
            LedState(false, false, false)
        };

        var led = new Led(10, 11, 12, new SysfsGpio());
        new Dancer (loop, led, states);

        loop.run();
        return 0;
    }
}

This article is available in PDF format for easy printing

Besides vala's type system (which is appropriated to the embedded application since it has no garbage collector, but better, it uses reference counting to control allocation and free) Vala is considered a modern language because of its high level features such as Generics, Asyncs, Code Attributes, Closures and Contract Programming.

It is mostly used in desktops applications, but in truth it has a some advantages that make it more well suited for some production embedded Linux applications than Python, Qt, Java or C#, because it is compiled and has very few dependencies. 

Next I'll pin point pros and cons comparing Vala to other high level programming languages available to embedded systems, based on my experience of building a product with it.

1. The dependencies

Vala compiler, itself, generates C code that relays on the GLib object system to implement its features, it is the only dependence to run raw Vala. GLib is available in most embedded Linux distros and distros generators (OpenWRT, Yocto, Raspbian, etc.). 

2. ABI compatible

ABI (Application Binary Interface) is how libraries are linked with, different from Python, C# and Java, Vala will link with any C/C++ application directly by the OS, no middle man.

3. Runtime performance and memory consumption

The wonderful of Vala is that it generates C, compiled by GCC or other compiler just the way you'd do with a C application, this is a jump ahead of performance compared to interpreted languages such as Python or languages that require Virtual environments such as C# and Java. This is huge point toward Vala, because the more computing power you need in a embedded platform, your costs go exponential. You can build big Vala applications and run it in a USD15 board such as Vocore. Actually, I have. Last product we used Vala was in a Vocore clone, a MIPS chip with 4MB of NOR storage plus 32MB of SRAM, and that was crucial to keep our BOM price low, which later increased our market competitiveness. What about Qt? It is also compiled, but the QtCore library alone took 7MB of storage and it was a no go on that MIPS platform. 

4. "Yeah, but... its a new language"

GLib is not new. It was created in 1998 and is the core of every GNOME product since then, the probability you will find bug in GLib's internal is very very low, what is new then? Vala compiler is the new thing, it is the software responsible to read Vala code and generate C code. I have found some weirdness in the Vala compiler, and you will probably find some too, but it is not big deal, Vala is highly stable and have been used by really big projects already, have a look at the Elementary OS.

Next part of the article I'll point about Vala's ecosystem, testing and graphic user interfaces. 

If you got interested in Vala, have a look at this demo embedded project, it is a Led Dancing Demo.

Also, I want to hear what you think! Let me know in comments. 

Thanks for reading!



Comments:

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Registering will allow you to participate to the forums on ALL the related sites and give you access to all pdf downloads.

Sign up
or Sign in