Vala (programming language)

Short description: Programming language

Vala

Paradigm| Multi-paradigm: imperative, structured, object-oriented
Developer| Jürg Billeter, Raffaele Sandrini
First appeared| 2006; 20 years ago (2006)
Stable release|

0.56.14 / 13 November 2023; 2 years ago (2023-11-13)

Typing discipline| Static, strong, inferred, structural
OS| Cross-platform all supported by GLib, but distributed as source code only.
License| LGPLv2.1+
Filename extensions| .vala, .vapi
Website| vala.dev
Influenced by
C, C++, C#, D, Java, Boo

Vala is an object-oriented programming language with a self-hosting compiler that generates C code and uses the GObject system.

Vala is syntactically similar to C# and includes notable features such as anonymous functions, signals, properties, generics, assisted memory management, exception handling, type inference, and foreach statements.[1] Its developers, Jürg Billeter and Raffaele Sandrini, wanted to bring these features to the plain C runtime with little overhead and no special runtime support by targeting the GObject object system. Rather than compiling directly to machine code or assembly language, it compiles to a lower-level intermediate language. It source-to-source compiles to C, which is then compiled with a C compiler for a given platform, such as GCC or Clang.[2]

Using functionality from native code libraries requires writing vapi files, defining the library interfaces. Writing these interface definitions is well-documented for C libraries. Bindings are already available for a large number of libraries, including libraries that are not based on GObject such as the multimedia library SDL and OpenGL.

## Contents

* 1 Description
* 2 History
* 3 Language design
* 3.1 Features
* 3.2 Memory management
* 3.3 Bindings
* 4 Tools
* 4.1 Editors
* 4.2 Code intelligence
* 4.3 Build systems
* 4.4 Debugging
* 5 Examples
* 5.1 Hello world
* 5.2 Object-oriented programming
* 5.3 Signals and callbacks
* 5.4 Threading
* 5.5 Graphical user interface
* 6 See also
* 7 References
* 8 External links

## Description

Vala is a programming language that combines the high-level build-time performance of scripting languages with the run-time performance of low-level programming languages. It aims to bring modern programming language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI, compared to applications and libraries written in C. The syntax of Vala is similar to C#, modified to better fit the GObject type system.[3]

## History

Vala was conceived by Jürg Billeter and was implemented by him and Raffaele Sandrini, who wished for a higher level alternative for developing GNOME applications instead of C. They did like the syntax and semantics of C# but did not want to use Mono, so they finished a compiler in May 2006. Initially, it was bootstrapped using C, and one year later (with release of version 0.1.0 in July 2007), the Vala compiler became self-hosted. As of 2021, the current stable release branch with long-term support is 0.48, and the language is under active development with the goal of releasing a stable version 1.0.[4]

Version  | Release date[5]

|

0.0.1  | 2006-07-15
0.1.0  | 2007-07-09
0.10.0  | 2010-09-18
0.20.0  | 2013-05-27
0.30.0  | 2015-09-18
0.40.0  | 2018-05-12
0.42.0  | 2018-09-01
0.44.0  | 2019-05-09
0.46.0  | 2019-09-05
0.48.0  | 2020-03-03
0.50.0  | 2020-09-10
0.52.0  | 2021-05-17
0.54.0  | 2021-09-16
0.56.14  | 2023-11-12
{{{2}}}
For old versions, only first point releases are listed

## Language design

### Features

Vala uses GLib and its submodules (GObject, GModule, GThread, GIO) as the core library, which is available for most operating systems and offers things like platform independent threading, input/output, file management, network sockets, plugins, regular expressions, etc. The syntax of Vala currently supports modern language features as follows:

* Interfaces
* Properties
* Signals
* Foreach
* Lambda expressions
* Type inference for local variables
* Generics
* Non-null types
* Assisted memory management
* Exception handling

Graphical user interfaces can be developed with the GTK GUI toolkit and the Glade GUI builder.

### Memory management

For memory management, the GType or GObject system provides reference counting. In C, a programmer must manually manage adding and removing references, but in Vala, managing such reference counts is automated if a programmer uses the language's built-in reference types rather than plain pointers. The only detail you need to worry about is to avoid generating reference cycles, because in that case this memory management system will not work correctly.[6]

Vala also allows manual memory management with pointers as an option.

### Bindings

Vala is intended to provide runtime access to existing C libraries, especially GObject-based libraries, without the need for runtime bindings. To use a library with Vala, all that needed is an API file (.vapi) containing the class and method declarations in Vala syntax. However, C++ libraries are not supported. At present, vapi files for a large part of the GNU project and GNOME platform are included with each release of Vala, including GTK. There is also a library called Gee, written in Vala, that provides GObject-based interfaces and classes for commonly used data structures.[7]

It should also be easily possible to write a bindings generator for access to Vala libraries from applications written in other languages, e.g., C#, as the Vala parser is written as a library, so that all compile-time information is available when generating a binding.

## Tools

### Editors

Tooling for Vala development has seen significant improvement over the recent years. The following is a list of some popular IDEs and text editors with plug-ins that add support for programming in Vala:

* GNOME Builder
* Visual Studio Code, with Vala plugin[8]
* Vim, with arrufat/vala.vim plugin[9]
* Emacs, with vala-mode[10]
* Atom
* Geany

### Code intelligence

Currently, there are two actively developing language servers which offer code intelligence for Vala as follows:

* , designed for any editor that supports LSP, including VSCode, vim, and GNOME Builder[11] * , currently the default language server for Vala in GNOME Builder and provides support to any editor with support for LSP[12]

### Build systems

Currently, there are a number of build systems supporting Vala, including Automake, CMake, Meson, and others.[13]

### Debugging

Debugging for Vala programs can be done with either GDB or LLDB. For debugging in IDEs,

* GNOME Builder has built-in debugging support for Vala with GDB.
* Visual Studio Code has extensions for GDB and LLDB, such as cpptools and CodeLLDB.[8]

## Examples

### Hello world

A simple "Hello, World!" program in Vala:

void main () {
print ("Hello World\n");

As can be noted, unlike C or C++, there are no header files in Vala. The linking to libraries is done by specifying `--pkg` parameters during compiling. Moreover, the GLib library is always linked and its namespace can be omitted (`print` is in fact `GLib.print`).

### Object-oriented programming

Below is a more complex version which defines a subclass `HelloWorld` inheriting from the base class `GLib.Object`, aka the GObject class. It shows some of Vala's object-oriented features:

class HelloWorld: Object {
private uint year = 0;

public HelloWorld () {

public HelloWorld.with_year (int year) {
if (year>0)
this.year = year;

public void greeting () {
if (year == 0)
print ("Hello World\n");
else
/* Strings prefixed with '@' are string templates. */
print (@"Hello World, $(this.year)\n");

void main (string[] args) {
var helloworld = new HelloWorld.with_year (2021);
helloworld.greeting ();

As in the case of GObject library, Vala does not support multiple inheritance, but a class in Vala can implement any number of interfaces, which may contain default implementations for their methods. Here is a piece of sample code to demonstrate a Vala interface with default implementation (sometimes referred to as a mixin)

using GLib;

interface Printable {
public abstract string print ();

public virtual string pretty_print () {
return "Please " + print ();

class NormalPrint: Object, Printable {
string print () {
return "don't forget about me";

class OverridePrint: Object, Printable {
string print () {
return "Mind the gap";

public override string pretty_print () {
return "Override";

void main (string[] args) {
var normal = new NormalPrint ();
var overridden = new OverridePrint ();

print (normal.pretty_print ());
print (overridden.pretty_print ());

### Signals and callbacks

Below is a basic example to show how to define a signal in a class that is not compact, which has a signal system built in by Vala through GLib. Then callback functions are registered to the signal of an instance of the class. The instance can emit the signal and each callback function (also referred to as handler) connected to the signal for the instance will get invoked in the order they were connected in:

class Foo {
public signal void some_event ();   // definition of the signal

public void method () {
some_event ();                  // emitting the signal (callbacks get invoked)

void callback_a () {
stdout.printf ("Callback A\n");

void callback_b () {
stdout.printf ("Callback B\n");

void main () {
var foo = new Foo ();
foo.some_event.connect (callback_a);      // connecting the callback functions
foo.some_event.connect (callback_b);
foo.method ();

### Threading

A new thread in Vala is a portion of code such as a function that is requested to be executed concurrently at runtime. The creation and synchronization of new threads are done by using the `Thread` class in GLib, which takes the function as a parameter when creating new threads, as shown in the following (very simplified) example:

int question(){
// Some print operations
for (var i = 0; i < 3; i++){
print (".");
Thread.usleep (800000);
stdout.flush ();

return 42;

void main () {
if (!Thread.supported ()) {
stderr.printf ("Cannot run without thread support.\n");
return;

print ("The Ultimate Question of Life, the Universe, and Everything");
// Generic parameter is the type of return value
var thread = new Thread<int> ("question", question);

print(@" $(thread.join ())\n");

### Graphical user interface

Below is an example using GTK to create a GUI "Hello, World!" program (see also GTK hello world) in Vala:

using Gtk;

int main (string[] args) {
Gtk.init (ref args);

var window = new Window ();
window.title = "Hello, World!";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size (350, 70);
window.destroy.connect (Gtk.main_quit);

var label = new Label ("Hello, World!");

window.add (label);
window.show_all ();

Gtk.main ();
return 0;

The statement `Gtk.main ()` creates and starts a main loop listening for events, which are passed along via signals to the callback functions. As this example uses the GTK package, it needs an extra `--pkg` parameter (which invokes pkg-config in the C backend) to compile:

valac --pkg gtk+-3.0 hellogtk.vala

## See also

* Genie, a programming language for the Vala compiler with a syntax closer to Python.
* Shotwell, an image organiser written in Vala.
* Geary, an email client written in Vala.
* elementary OS, a Linux distribution with a desktop environment programmed mostly in Vala.
* Budgie, a Linux desktop environment programmed mostly in Vala.

## References

1. ↑ "Vala: high-level programming with less fat". Ars Technica. 2 September 2007. https://arstechnica.com/information-technology/2007/09/vala-high-level-programming-with-less-fat/.
2. ↑ "A look at two new languages: Vala and Clojure". https://lwn.net/Articles/335966/.
3. ↑ "Vala· GitLab". GNOME. https://gitlab.gnome.org/GNOME/vala/.
4. ↑ Michael Lauer (2019). Introducing Vala Programming. doi:10.1007/978-1-4842-5380-9. ISBN 978-1-4842-5379-3. https://link.springer.com/book/10.1007/978-1-4842-5380-9. Retrieved 16 March 2021.
5. ↑ "Vala Releases". Vala Project. https://gitlab.gnome.org/GNOME/vala/-/tags.
6. ↑ "Vala's Memory Management Explained". https://wiki.gnome.org/Projects/Vala/ReferenceHandling.
7. ↑ "Libgee on Gitlab". https://gitlab.gnome.org/GNOME/libgee/.
8. ↑ 8.0 8.1 "Coding in Vala with Visual Studio Code". https://wiki.gnome.org/Projects/Vala/Tools/VisualStudioCode.
9. ↑ "Coding in Vala with the Vim Text Editor". https://wiki.gnome.org/Projects/Vala/Tools/Vim.
10. ↑ "Enable Vala syntax highlighting and code browser support in GNU Emacs". https://wiki.gnome.org/Projects/Vala/Emacs.
11. ↑ "benwaffle/vala-language-server on Github". https://github.com/benwaffle/vala-language-server.
12. ↑ "esodan/gvls on GitLab". https://gitlab.gnome.org/esodan/gvls.
13. ↑ "Vala Tools". https://wiki.gnome.org/Projects/Vala/Tools.

## External links

* GNOME Wiki Page
* API Documentation
* Vala repository on GNOME · GitLab
* LibGee, a utility library for Vala.
* Vala sample code for beginners
* List of Vala programs
* Autovala, a program that automatizes and simplifies creating CMake and Meson files for Vala/C projects
* The Vala community on GitHub
* Akira \- Linux native designer tool
* Kangaroo \- Cross-platform database client tool for popular databases

Comparison with other languages

* Vala and Java
* Vala and C#
* Benchmarks of different languages, including Vala

* v
* t
* e

GNOME

Core Applications|

* Boxes
* Calculator
* Character Map
* Dictionary
* Disks
* Files
* Software
* Terminal
* Videos
* Web

Extras|

| Development|

* Anjuta
* Builder
* Glade Interface Designer
* Meld
* GNOME Devhelp
* Nemiver
* Geany
* Gtranslator

|

Office|

* AbiWord
* Dia
* Evince
* Evolution
* GNOME LaTeX
* Gnumeric
* OCRFeeder

Graphics|

* Eye of GNOME
* F-Spot
* GIMP
* gThumb
* Inkscape
* Shotwell
* Simple Scan

Internet|

* Balsa
* Empathy
* Ekiga
* Geary
* GNOME Fractal
* Gobby
* Jami
* Vino
* Vinagre
* Transmission-gtk

Media|

* Banshee
* Cheese
* EasyTag
* Pitivi
* Rhythmbox
* Sound Juicer
* SoundConverter
* sushi

Games|

* GNOME Games
* Chess
* Mines
* gbrainy
* PyChess

Utilities|

* Archive Manager
* Brasero
* dconf-editor
* gedit
* gnote
* GNOME System Tools
* GParted
* Tomboy

Components|

| User interface|

| GNOME 4|

* Mutter on GSK
* GNOME Shell 2
* …

|

GNOME 3|

* Client-Side Decoration
* GDM
* Mutter
* GNOME Shell
* Tango Desktop Project
* Orca

GNOME 2|

* Metacity
* GNOME Panel
* Clearlooks

Other|

* Cinnamon
* MATE
* Diodon
* GNOME Do
* Avant Window Navigator

GNOME Base|

* GTK
* GDK
* GSK
* ATK
* Clutter
* Pango
* GLib
* GObject
* GIO
* IBus

Other|

* dconf
* Genie
* Keyring
* GNOME-DB
* GVfs
* GnomeVFS
* Librsvg
* Tracker
* Vala
* libxslt
* libxml2

freedesktop.org|

* AppStream
* D-Bus
* GStreamer
* NetworkManager
* Poppler
* Wayland
* X.Org Server
* PulseAudio
* PackageKit
* HarfBuzz
* Cairo

Community|

* GNOME Foundation
* GUADEC
* The GNOME Project
* Outreachy

People|

* Miguel de Icaza
* Luis Villa
* Havoc Pennington
* Karen Sandler

* Category
* Commons
* WikiProject

* v
* t
* e

C programming language

* ANSI C
* C89 and C90
* C99
* C11
* C18
* C2x
* Embedded C
* MISRA C

Features|

* Functions
* Header files
* Libraries
* Operators
* String
* Syntax
* Preprocessor
* Data types

Standard library
functions|

* Char (ctype.h)
* File I/O (stdio.h)
* Math (math.h)
* Dynamic memory (stdlib.h)
* String (string.h)
* Time (time.h)
* Variadic (stdarg.h)
* POSIX

Standard
libraries|

* Bionic
* libhybris
* dietlibc
* EGLIBC
* glibc
* klibc
* Microsoft Run-time Library
* musl
* Newlib
* uClibc
* BSD libc

Compilers|

* Comparison of compilers
* ACK
* Borland Turbo C
* Clang
* GCC
* ICC
* LCC
* PCC
* SDCC
* TCC
* Microsoft Visual Studio / Express / C++
* Watcom C/C++

IDEs|

* Comparison of IDEs
* Anjuta
* Code
* CodeLite
* Eclipse
* Geany
* Microsoft Visual Studio
* NetBeans

Comparison with
other languages|

* Compatibility of C and C++
* Comparison with Embedded C
* Comparison with Pascal
* Comparison of programming languages

Descendant
languages|

* C++
* C#
* D
* Objective-C
* Alef
* Limbo
* Go
* Vala

* Category

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Vala (programming language). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Vala_(programming_language)&oldid=197537"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template