World Library  
Flag as Inappropriate
Email this Article

Vala (programming language)

 

Vala (programming language)

Vala
Paradigm(s) Multi-paradigm: imperative, structured, object-oriented
Developer Jürg Billeter, Raffaele Sandrini
Appeared in 2006
Stable release 0.26.1[1] / 13 October 2014 (2014-10-13)
Typing discipline static, strong
Influenced by C, C++, C#, D, Java, Python
OS Cross-platform all supported by GLib, but distributed as source code only.
License LGPL 2.1+
Filename extension(s) .vala, .vapi
Website /Vala/Projects.org.gnomewiki

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 several features such as: anonymous functions, signals, properties, generics, assisted memory management, exception handling, type inference, and foreach statements.[2] Its developers Jürg Billeter and Raffaele Sandrini aim 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 being compiled directly to assembly or to another intermediate language, Vala is source-to-source compiled to C, which is then compiled with a platform's standard C compiler, such as GCC.[3]

For memory management, the 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.

Using functionality from native code libraries requires writing vapi files, defining the library interfacing. Writing these interface definitions is well-documented for C libraries, especially when based on GObject. However, C++ libraries are not supported. Vapi files are provided for a large portion of the GNOME platform, including GTK+.

Vala was conceived by Jürg Billeter and was implemented by him and Raffaele Sandrini, finishing a self-hosting compiler in May 2006.[4]

Contents

  • Code example 1
  • IDE support 2
  • See also 3
  • References 4
  • External links 5

Code example

A simple "Hello, World!" program (see also GTK+ hello world)

int main () {
    print ("Hello World\n");
    
    return 0;
}

A more complex version, showing some of Vala's object-oriented features:

class Sample : Object {
    void greeting () {
        stdout.printf ("Hello World\n");
    }
    
    static void main (string[] args) {
        var sample = new Sample ();
        sample.greeting ();
    }
}

An example using GTK+ to create a GUI "Hello, World!" program:

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 last example needs an extra parameter to compile on GNOME3 platforms:

valac --pkg gtk+-3.0 hellogtk.vala

This is the converted C code:

/* hellogtk.c generated by valac 0.22.0, the Vala compiler
 * generated from hellogtk.vala, do not modify */

#include 
#include 
#include 
#include 
#include 

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

gint _vala_main (gchar** args, int args_length1);
static void _gtk_main_quit_gtk_widget_destroy (GtkWidget* _sender, gpointer self);

static void _gtk_main_quit_gtk_widget_destroy (GtkWidget* _sender, gpointer self) {
        gtk_main_quit ();
}

gint _vala_main (gchar** args, int args_length1) {
        gint result = 0;
        GtkWindow* window = NULL;
        GtkWindow* _tmp0_ = NULL;
        GtkLabel* label = NULL;
        GtkLabel* _tmp1_ = NULL;
        gtk_init (&args_length1, &args);
        _tmp0_ = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL);
        g_object_ref_sink (_tmp0_);
        window = _tmp0_;
        gtk_window_set_title (window, "Hello, World!");
        gtk_container_set_border_width ((GtkContainer*) window, (guint) 10);
        g_object_set (window, "window-position", GTK_WIN_POS_CENTER, NULL);
        gtk_window_set_default_size (window, 350, 70);
        g_signal_connect ((GtkWidget*) window, "destroy", (GCallback) _gtk_main_quit_gtk_widget_destroy, NULL);
        _tmp1_ = (GtkLabel*) gtk_label_new ("Hello, World!");
        g_object_ref_sink (_tmp1_);
        label = _tmp1_;
        gtk_container_add ((GtkContainer*) window, (GtkWidget*) label);
        gtk_widget_show_all ((GtkWidget*) window);
        gtk_main ();
        result = 0;
        _g_object_unref0 (label);
        _g_object_unref0 (window);
        return result;
}

int main (int argc, char ** argv) {
        g_type_init ();
        return _vala_main (argv, argc);
}

IDE support

There are various projects in various states of stability in order to provide IDE support for Vala:

See also

  • Genie, a programming language for the Vala compiler with a syntax closer to Python
  • Shotwell, an image organiser written in Vala
  • Ease, a presentation program written in Vala
  • elementary OS, a Linux distribution with a desktop environment programmed mostly in Vala

References

  1. ^ "Vala Releases". 13 October 2014. 
  2. ^ "Vala: high-level programming with less fat".  
  3. ^ "A look at two new languages: Vala and Clojure". 
  4. ^ "Writing Multimedia Applications with Vala". Archived from the original on 28 August 2012. 
  5. ^ "Vala specific section,Vala Documentation". 
  6. ^ "Source code of Val(a)IDE". 
  7. ^ https://github.com/Valama/valama

External links

  • Official website , on GNOME Live!
  • ValaToWindows, Vala compiled binaries for Windows.
  • LibGee, a collection library for vala.
  • Val(a)IDE, an IDE for Vala
  • Valencia, a Vala plugin for Gedit
  • Vala Toys for Gedit, a plugin for Gedit that adds support of autocompletion and more, to program with Vala.
  • API Documentation
  • Vala sample code for beginners.
  • List of Vala programs
Comparison with other languages
  • Vala and Java
  • Vala and C#
  • Benchmark of Vala versus C# and C
  • More Vala benchmarks
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.