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.valaThis is the converted C code:
/* hellogtk.c generated by valac 0.20.1, the Vala compiler * generated from hellogtk.vala, do not modify */ #includeRead more about this topic: Vala (programming Language)
Famous quotes containing the word code:
“Wise Draco comes, deep in the midnight roll
Of black artillery; he comes, though late;
In code corroborating Calvins creed
And cynic tyrannies of honest kings;
He comes, nor parlies; and the Town, redeemed,
Gives thanks devout; nor, being thankful, heeds
The grimy slur on the Republics faith implied,
Which holds that Man is naturally good,
Andmoreis Natures Roman, never to be
scourged.”
—Herman Melville (18191891)
“...I had grown up in a world that was dominated by immature age. Not by vigorous immaturity, but by immaturity that was old and tired and prudent, that loved ritual and rubric, and was utterly wanting in curiosity about the new and the strange. Its era has passed away, and the world it made has crumbled around us. Its finest creation, a code of manners, has been ridiculed and discarded.”
—Ellen Glasgow (18731945)