Vala (programming language)
   HOME

TheInfoList



OR:

Vala is an
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
with a self-hosting compiler that generates C code and uses the
GObject The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C programs to provide object-oriented C-based APIs ...
system. Vala is
syntactically In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituency) ...
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: Mathematics * Property (mathematics) Philosophy and science * Property (philosophy), in philosophy an ...
,
generics Generic or generics may refer to: In business * Generic term, a common name used for a range or class of similar things not protected by trademark * Generic brand, a brand for a product that does not have an associated brand or trademark, other ...
, 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 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 branches of computer science and linguistic ...
, 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
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ...
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. Using functionality from native code
libraries A library is a collection of Document, materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or electronic media, digital access (soft copies) materials, and may be a ...
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'' * '' Int ...
. Writing these interface definitions is well-documented for C libraries, especially when based on GObject. Bindings are already available for a large number of libraries, including for C libraries that are not based on GObject, such as the multimedia library SDL,
OpenGL OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
, etc.


Description

Vala is a programming language that combines the
high-level High-level and low-level, as technical terms, are used to classify, describe and point to specific goals of a systematic operation; and are applied in a wide range of contexts, such as, for instance, in domains as widely varied as computer scien ...
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, first introduced by Paracelsus in the 16th century and later adopted by more recent authors including those of modern fantasy literature. Its characte ...
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, first introduced by Paracelsus in the 16th century and later adopted by more recent authors including those of modern fantasy literature. Its characte ...
applications instead of C. They did like the syntax and semantics of C# but did not want to use
Mono Mono may refer to: Common meanings * Infectious mononucleosis, "the kissing disease" * Monaural, monophonic sound reproduction, often shortened to mono * Mono-, a numerical prefix representing anything single Music Performers * Mono (Japanes ...
, so they finished a compiler in May 2006. Initially, it was
bootstrapped In general, bootstrapping usually refers to a self-starting process that is supposed to continue or grow without external input. Etymology Tall boots may have a tab, loop or handle at the top known as a bootstrap, allowing one to use fingers ...
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 Long-term support (LTS) is a product lifecycle management policy in which a stable release of computer software is maintained for a longer period of time than the standard edition. The term is typically reserved for open-source software, where i ...
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, 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, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
and offers things like platform independent threading,
input/output In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system. Inputs are the signals ...
,
file management A file manager or file browser is a computer program that provides a user interface to manage files and folders. The most common operations performed on files or groups of files include creating, opening (e.g. viewing, playing, editing or p ...
,
network sockets A network socket is a software structure within a network node of a computer network that serves as an endpoint for sending and receiving data across the network. The structure and properties of a socket are defined by an application programmin ...
, plugins, regular expressions, 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'' * '' Int ...
*
Properties Property is the ownership of land, resources, improvements or other tangible objects, or intellectual property. Property may also refer to: Mathematics * Property (mathematics) Philosophy and science * Property (philosophy), in philosophy an ...
* Signals * Foreach * Lambda expressions * Type inference for local variables *
Generics Generic or generics may refer to: In business * Generic term, a common name used for a range or class of similar things not protected by trademark * Generic brand, a brand for a product that does not have an associated brand or trademark, other ...
* 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 can be developed with the GTK
GUI toolkit The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, inste ...
and the Glade GUI builder.


Memory management

For memory management, the GType or GObject system provides
reference counting In computer science, reference counting is a programming technique of storing the number of references, pointers, or handles to a resource, such as an object, a block of memory, disk space, and others. In garbage collection algorithms, refer ...
. 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. 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 GNU () is an extensive collection of free software (383 packages as of January 2022), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operat ...
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 In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, ...
. 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 GNOME Builder is a general purpose integrated development environment (IDE) for the GNOME platform, primarily designed to aid in writing GNOME-based applications. It was initially released on March 24, 2015. The application's tagline is "A toolsm ...
* Visual Studio Code, with Vala plugin * Vim, with arrufat/vala.vim 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, ...
, with vala-mode *
Atom Every atom is composed of a nucleus and one or more electrons bound to the nucleus. The nucleus is made of one or more protons and a number of neutrons. Only the most common variety of hydrogen has no neutrons. Every solid, liquid, gas, a ...
* 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 In software development, GNU Automake is a programming tool to automate parts of the compilation process. It eases usual compilation problems. For example, it points to needed dependencies. It automatically generates one or more ''Makefile.in ...
,
CMake In software development, CMake is cross-platform free and open-source software for build automation, testing, packaging and installation of software by using a compiler-independent method. CMake is not a build system itself; it generates a ...
,
Meson In particle physics, a meson ( or ) 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, ...
, and others.


Debugging

Debugging for Vala programs can be done with either GDB or LLDB. For debugging in IDEs, *
GNOME Builder GNOME Builder is a general purpose integrated development environment (IDE) for the GNOME platform, primarily designed to aid in writing GNOME-based applications. It was initially released on March 24, 2015. The application's tagline is "A toolsm ...
has built-in debugging support for Vala with GDB. * Visual Studio Code has extensions for GDB and LLDB, such as cpptools and CodeLLDB.


Examples


Hello world

A 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 Document, materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or electronic media, digital access (soft copies) materials, and may be a ...
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 library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C programs to provide object-oriented C-based APIs ...
class. It shows some of Vala's
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
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'' * '' Int ...
, 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 to create a
GUI The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, inste ...
"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 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 elementary OS is a Linux distribution based on Ubuntu LTS. It promotes itself as a "thoughtful, capable, and ethical" replacement to macOS and Windows and has a pay-what-you-want model. The operating system, the desktop environment (called Pa ...
, 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 Page

API Documentation

Vala
repository on
GNOME A gnome is a mythological creature and diminutive spirit in Renaissance magic and alchemy, first introduced by Paracelsus in the 16th century and later adopted by more recent authors including those of modern fantasy literature. Its characte ...
·
GitLab GitLab Inc. is an open-core company that operates GitLab, a DevOps software package which can develop, secure, and operate software. The open source software project was created by Ukrainian developer Dmitriy Zaporozhets and Dutch developer ...

LibGee
a utility library for Vala.
Vala sample code for beginners

List of Vala programs


* ttps://github.com/vala-lang/ 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
{{CProLang Programming languages Object-oriented programming languages Software using the LGPL license Source-to-source compilers Statically typed programming languages Programming languages created in 2006 2006 software Cross-platform free software