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:
“Hollywood keeps before its child audiences a string of glorified young heroes, everyone of whom is an unhesitating and violent Anarchist. His one answer to everything that annoys him or disparages his country or his parents or his young lady or his personal code of manly conduct is to give the offender a sock in the jaw.... My observation leads me to believe that it is not the virtuous people who are good at socking jaws.”
—George Bernard Shaw (18561950)
“Acknowledge your will and speak to us all, This alone is what I will to be! Hang your own penal code up above you: we want to be its enforcers!”
—Friedrich Nietzsche (18441900)