Vala is an
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
with a
self-hosting compiler that generates
C code and uses the
GObject
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
system.
Vala is
syntactically similar to
C# and includes notable features such as
anonymous functions,
signals,
properties
Property is the ownership of land, resources, improvements or other tangible objects, or intellectual property.
Property may also refer to:
Philosophy and science
* Property (philosophy), in philosophy and logic, an abstraction characterizing an ...
,
generics,
assisted memory management,
exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
,
type inference
Type inference, sometimes called type reconstruction, refers to the automatic detection of the type of an expression in a formal language. These include programming languages and mathematical type systems, but also natural languages in some bran ...
, and
foreach statements. 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
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
object system. Rather than compiling directly to machine code or assembly language, it compiles to a lower-level
intermediate language
An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
. It
source-to-source compiles to C, which is then compiled with a C compiler for a given platform, such as
GCC or
Clang
Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
.
Using functionality from native code
libraries
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
requires writing vapi files, defining the library
interfaces
Interface or interfacing may refer to:
Academic journals
* ''Interface'' (journal), by the Electrochemical Society
* '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics''
* '' Inter ...
. 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
OpenGL (Open Graphics Library) is a Language-independent specification, cross-language, cross-platform application programming interface (API) for rendering 2D computer graphics, 2D and 3D computer graphics, 3D vector graphics. The API is typic ...
.
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
A gnome () is a mythological creature and diminutive spirit in Renaissance magic and alchemy, introduced by Paracelsus in the 16th century and widely adopted by authors, including those of modern fantasy literature. They are typically depict ...
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.
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
A gnome () is a mythological creature and diminutive spirit in Renaissance magic and alchemy, introduced by Paracelsus in the 16th century and widely adopted by authors, including those of modern fantasy literature. They are typically depict ...
applications instead of C. They liked 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. In 2008, the Genie language was created to expose a
Python-like syntax to the Vala compiler. 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.
Language design
Features
Vala uses GLib and its submodules (
GObject
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
, GModule, GThread, GIO) as the core library, which is available for most
operating systems
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
and offers things like platform independent
threading,
input/output
In computing, input/output (I/O, i/o, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, such as another computer system, peripherals, or a human operator. Inputs a ...
,
file management,
network sockets,
plugins,
regular expressions
A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of character (computing), characters that specifies a pattern matching, match pattern in string (computer science), text. Usually ...
, etc. The syntax of Vala currently supports modern language features as follows:
*
Interfaces
Interface or interfacing may refer to:
Academic journals
* ''Interface'' (journal), by the Electrochemical Society
* '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics''
* '' Inter ...
*
Properties
Property is the ownership of land, resources, improvements or other tangible objects, or intellectual property.
Property may also refer to:
Philosophy and science
* Property (philosophy), in philosophy and logic, an abstraction characterizing an ...
*
Signals
*
Foreach
*
Lambda expressions
*
Type inference for local variables
*
Generics
*
Non-null types
*
Assisted memory management
*
Exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
Graphical user interfaces
A graphical user interface, or GUI, is a form of user interface that allows user (computing), users to human–computer interaction, interact with electronic devices through Graphics, graphical icon (computing), icons and visual indicators such ...
can be developed with the
GTK
GTK (formerly GIMP ToolKit and GTK+) is a free software cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both Free software, free and ...
GUI toolkit and the
Glade GUI builder
A graphical user interface builder (or GUI builder), also known as GUI designer or sometimes RAD IDE, is a software development tool that simplifies the creation of graphical user interface, GUIs by allowing the designer to arrange graphical cont ...
.
Memory management
For memory management, the GType or
GObject
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
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 one needs to worry about is to avoid generating
reference cycles, because in that case this memory management system will not work correctly.
Vala also allows manual memory management with
pointers
Pointer may refer to:
People with the name
* Pointer (surname), a surname (including a list of people with the name)
* Pointer Williams (born 1974), American former basketball player
Arts, entertainment, and media
* ''Pointer'' (journal), the ...
as an option.
Bindings
Vala is intended to provide runtime access to existing C libraries, especially
GObject
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
-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
GTK (formerly GIMP ToolKit and GTK+) is a free software cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both Free software, free and ...
. There is also a library called Gee, written in Vala, that provides
GObject
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
-based interfaces and classes for commonly used
data structure
In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
s.
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 editor
A text editor is a type of computer program that edits plain text. An example of such program is "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be used to c ...
s with plug-ins that add support for programming in Vala:
*
GNOME Builder
*
Visual Studio Code
Visual Studio Code, commonly referred to as VS Code, is an integrated development environment developed by Microsoft for Windows, Linux, macOS and web browsers. Features include support for debugging, syntax highlighting, intelligent code comp ...
, with Vala plugin
*
Vim, with plugin
*
Emacs
Emacs (), originally named EMACS (an acronym for "Editor Macros"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, s ...
, with vala-mode
*
Atom
Atoms are the basic particles of the chemical elements. An atom consists of a atomic nucleus, nucleus of protons and generally neutrons, surrounded by an electromagnetically bound swarm of electrons. The chemical elements are distinguished fr ...
*
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
* , currently the default language server for Vala in GNOME Builder and provides support to any editor with support for
LSP
Build systems
Currently, there are a number of
build systems supporting Vala, including
Automake,
CMake,
Meson
In particle physics, a meson () is a type of hadronic subatomic particle composed of an equal number of quarks and antiquarks, usually one of each, bound together by the strong interaction. Because mesons are composed of quark subparticles, the ...
, and others.
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
Visual Studio Code, commonly referred to as VS Code, is an integrated development environment developed by Microsoft for Windows, Linux, macOS and web browsers. Features include support for debugging, syntax highlighting, intelligent code comp ...
has extensions for
GDB and
LLDB, such as cpptools and CodeLLDB.
Examples
Hello world
simple "
Hello, World!" program in Vala:
void main ()
As can be noted, unlike C or C++, there are no header files in Vala. The linking to
libraries
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
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
The GLib Object System, or GObject, is a free software, free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C (programming language), C programs ...
class. It shows some of Vala's
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
features:
class HelloWorld: Object
void main (string[] args)
As in the case of GObject#Comparisons to other object systems, GObject library, Vala does not support multiple inheritance, but a class in Vala can implement any number of
interfaces
Interface or interfacing may refer to:
Academic journals
* ''Interface'' (journal), by the Electrochemical Society
* '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics''
* '' Inter ...
, 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
class NormalPrint: Object, Printable
class OverridePrint: Object, Printable
void main (string[] args)
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
void callback_a ()
void callback_b ()
void main ()
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()
void main ()
Graphical user interface
Below is an example using
GTK
GTK (formerly GIMP ToolKit and GTK+) is a free software cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both Free software, free and ...
to create a
GUI "Hello, World!" program (see also
GTK hello world) in Vala:
using Gtk;
int main (string[] args)
The statement
Gtk.main ()
creates and starts a Event loop, main loop listening for events, which are passed along via signals to the callback functions. As this example uses the
GTK
GTK (formerly GIMP ToolKit and GTK+) is a free software cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both Free software, free and ...
package, it needs an extra
--pkg
parameter (which invokes
pkg-config
pkg-config is a software development tool that queries information about libraries from a local, file-based database for the purpose of building a codebase that depends on them. It allows for sharing a codebase in a cross-platform way by using ...
in the C
backend) to compile:
valac --pkg gtk+-3.0 hellogtk.vala
See also
*
Shotwell, an image organiser written in Vala.
*
Geary, an email client written in Vala.
*
elementary OS
Elementary OS (stylized as elementary OS) is a Linux distribution based on Ubuntu LTS. It promotes itself as a "thoughtful, capable, and ethical" replacement to macOS and Microsoft Windows, Windows and has a pay what you want, pay-what-you-wan ...
, a Linux distribution with a desktop environment programmed mostly in Vala.
*
Budgie, a Linux desktop environment programmed mostly in Vala.
References
External links
*
GNOME Wiki PageAPI DocumentationValarepository on
GNOME
A gnome () is a mythological creature and diminutive spirit in Renaissance magic and alchemy, introduced by Paracelsus in the 16th century and widely adopted by authors, including those of modern fantasy literature. They are typically depict ...
·
GitLab
GitLab is a software forge primarily developed by GitLab Inc. It is available as a community edition and a commercial edition.
History
GitLab was created in 2011 by Ukrainian programmer Dmitriy Zaporozhets as a side project written in Rub ...
LibGee a utility library for Vala.
Vala sample code for beginnersList of Vala programs*
ttps://github.com/vala-lang/ The Vala community on GitHubAkira- Linux native designer tool
Kangaroo- Cross-platform database client tool for popular databases
;Comparison with other languages
Vala and JavaVala and C#Benchmarks of different languages, including Vala
{{CProLang
Programming languages
Object-oriented programming languages
Software using the GNU Lesser General Public License
Source-to-source compilers
Statically typed programming languages
Programming languages created in 2006
2006 software
Cross-platform free software