Vala
lastmod 2020-03-08created 2020-03-081 edits
Vala - Compiler Using the GObject Type System.
About
valac, the Vala compiler, is a self-hosting compiler that translates Vala source code into C source and header files. valac uses the GObject system to create the classes and interfaces declared in Vala source code.
Vala's syntax is similar to C#, but modified to better suit the GObject system. Vala offers the following modern programming language features:
- Interfaces
- Properties
- Signals
- Foreach
- Lambda expressions
- Type inference for local variables
- Generics
- Non-null types
- Assisted memory management
- Type modules (plugins)
Vala is designed to allow access to existing C libraries (especially GObject-based libraries) without runtime bindings. All that is needed to use a library with Vala is an API file with the class and method definitions written in Vala syntax. Vala currently ships with bindings for GLib, GTK+, and many other libraries of the GNOME platform.
Using classes and methods written in Vala from C is not difficult. Just install the automatically generated header files, and C applications can access Vala libraries through the usual GObject-based APIs. Also, because the Vala parser is written as a library and all compile-time information is available when generating bindings, it is very easy to write bindings for accessing Vala libraries from applications written in C# and other languages.
Why use Vala?
Many developers wanted to write GNOME applications and libraries in a higher-level programming language. But for various reasons they could not use C# or Java, and kept using C, which has no syntax supporting the GObject type system. The Vala compiler lets developers write complex object-oriented code quickly while keeping the standard C API and ABI and using little memory.
C# and Java libraries cannot be used like Native GObject libraries written in C or other languages, and cannot be included as part of the GNOME platform. Managed applications may be unusable in some situations because of their high memory usage.
valac generates C source and header files from Vala source files, as if the developer had written the library or application directly in C. Using a Vala library from a C application is hardly different from using any other GObject-based library. Since there is no Vala runtime library, applications can distribute the generated C code when providing a tarball, and users need no additional dependencies at run or build time.