请输入您要查询的百科知识:

 

词条 Vala (programming language)
释义

  1. Code example

  2. See also

  3. References

  4. External links

{{Use dmy dates|date=August 2015}}{{Infobox programming language
| name = Vala
| logo = File:Vala Logo.svg
| paradigm = Multi-paradigm: imperative, structured, object-oriented
| developer = Jürg Billeter, Raffaele Sandrini
| latest release version = 0.42.3[1]
| latest release date = {{Start date and age|2018|11|7|df=yes}}
| latest preview version = 0.41.92
| latest preview date = {{Start date and age|2018|8|18|df=yes}}
| typing = static, strong
| influenced by = C, C++, C#, D, Java, Boo
| operating system = Cross-platform all supported by GLib, but distributed as source code only.
| license = LGPL 2.1+
| website = {{URL|https://wiki.gnome.org/Projects/Vala}}
| year = {{Start date and age|df=yes|2006}}
| file ext = .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 notable 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, wanted 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 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.[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]

Code example

A simple "Hello, World!" Vala program:

void main () {

}

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

class Sample : Object {

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

}

An example using GTK+ to create a GUI "Hello, World!" program (see also GTK+ hello world):

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 GNOME 3 platforms:

valac --pkg gtk+-3.0 hellogtk.vala

See also

{{Portal|Free and open-source software}}
  • 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, a Linux distribution with a desktop environment programmed mostly in Vala.

References

1. ^{{cite web|url=https://wiki.gnome.org/Projects/Vala|title=Vala - Compiler Using the GObject Type System|accessdate=11 November 2018|at=News section|publisher=GNOME Project}}
2. ^{{cite web|url=https://arstechnica.com/information-technology/2007/09/vala-high-level-programming-with-less-fat/|title=Vala: high-level programming with less fat|publisher=Ars Technica|accessdate=13 December 2011}}
3. ^{{cite web|url=https://lwn.net/Articles/335966/|title=A look at two new languages: Vala and Clojure}}
4. ^{{cite web|url=http://gnomejournal.org/article/80/writing-multimedia-applications-with-vala|title=Writing Multimedia Applications with Vala|archiveurl=https://web.archive.org/web/20120828170152/http://www.gnomejournal.org/article/80/writing-multimedia-applications-with-vala|archivedate=28 August 2012|deadurl=yes}}

External links

{{Wikibooks|Vala Programming}}{{commons category|Vala (programming language)}}
  • {{Official website|https://wiki.gnome.org/Projects/Vala}}
  • [https://sourceforge.net/projects/valatowindows/ ValaToWindows], Vala compiled binaries for Windows
  • [https://wiki.gnome.org/Projects/Libgee LibGee], a collection library for Vala.
  • API Documentation
  • Vala sample code for beginners
  • [https://wiki.gnome.org/Projects/Vala/Documentation#Projects_Developed_in_Vala List of Vala programs]
  • [https://code.google.com/p/web-vala/wiki/GettingStarted web-vala], a simple web application framework for Vala
Comparison with other languages
  • [https://wiki.gnome.org/Projects/Vala/ValaForJavaProgrammers Vala and Java]
  • [https://wiki.gnome.org/Projects/Vala/ValaForCSharpProgrammers Vala and C#]
  • [https://code.google.com/p/vala-benchmarks/ Benchmark of Vala versus C# and C]
  • [https://code.google.com/p/vala-benchmarks/wiki/BenchResults More Vala benchmarks]
{{GNOME}}{{CProLang}}

9 : Programming languages|Object-oriented programming languages|Software using the LGPL license|Source-to-source compilers|Statically typed programming languages|Vala (programming language)|Programming languages created in 2006|2006 software|Cross-platform free software

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/17 15:04:16