Informatika Komputer    
   
Daftar Isi
(Sebelumnya) Vacuum tubeValor por Tamaulipas (Berikutnya)

Vala (programming language)

Vala
Paradigm(s)Multi-paradigm: imperative, structured, object-oriented
Appeared in2006
DeveloperJürg Billeter, Raffaele Sandrini
Stable release0.19.0[1] (20 February 2013; 25 days ago (2013-02-20))
Typing disciplinestatic, strong
Influenced byC, C++, C#, D, Java, Python
OScross-platform all supported by GLib, but distributed as source code only.
LicenseLGPL 2.1+
Usual filename extensions.vala, .vapi

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 useful language features like 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 currently[when?] 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

A simple "Hello, World!" program:

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.14.2, the Vala compiler * generated from hellogtk.vala, do not modify */  #include <glib.h>#include <glib-object.h>#include <stdlib.h>#include <string.h>#include <gtk/gtk.h> #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* _tmp0_; GtkWindow* _tmp1_; GtkWindow* window; GtkLabel* _tmp2_; GtkLabel* _tmp3_; GtkLabel* label; gtk_init (&args_length1, &args); _tmp0_ = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL); _tmp1_ = g_object_ref_sink (_tmp0_); window = _tmp1_; 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); _tmp2_ = (GtkLabel*) gtk_label_new ("Hello, World!"); _tmp3_ = g_object_ref_sink (_tmp2_); label = _tmp3_; 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
  • MonoDevelop, a programming IDE that runs on Linux, Windows and Mac OS X[5] with support for Vala
  • Geary, an email client written in Vala
  • Shotwell, an image organiser written in Vala
  • Ease, a presentation program written in Vala

References

  1. ^ "Vala Releases". 20 February 2013. http://live.gnome.org/Vala/Release.
  2. ^ Vala: high-level programming with less fat - Ars Technica. Retrieved Dec13, 2011 1:40PM EST
  3. ^ http://lwn.net/Articles/335966/
  4. ^ http://gnomejournal.org/article/80/wr iting-multimedia-applications-with-va la
  5. ^ multiple OS support

External links

Comparison with other languages
(Sebelumnya) Vacuum tubeValor por Tamaulipas (Berikutnya)