The Genie language

Page updated November 5, 2009
There is not yet an official logo for Genie/Vala, above image is a contender, created by Wolter Hellmund.
These Genie/Vala pages are no longer being updated, as I have defected. I have found BaCon to be more suited to my purposes:


Vala and Genie are new programming languages, really new. Vala came first, in mid-2006, with a C#-like syntax, followed by Genie in mid-2008 with a Python-Boo-like syntax. These languages use the same compiler and support all the same features, so take your pick!

If you happen to like the C/C# syntax, fine, go for Vala, and here is the home page:

Genie offers a simpler syntax, great for those of us who want to make the coding experience as painless as possible. Everything that you read on the Vala pages applies to Genie, it is just that The Vala compiler accepts this alternative simpler syntax. All features, generated code, etc., is exacty the same as for Vala coding.

However, Genie being so new, documentation is sparse. I was struggling a bit at first, so I thought why not write tutorials as I go along, so that others will find getting started with Genie to be a most pleasant experience? Hence this page and others linked below. This will grow in time, and if anyone wants to contribute, please do!

Here is the Genie home page:

However, do we need another language, or in this case two more? Since we already have the easy-to-use Python language, with so much developer support, why am I even bothering to learn a brand-new unknown language?...

Why not Python?

To answer this question, I have to explain where I am at, and why I was looking around for another language to learn.

I created the Puppy Linux project in 2003 and since then I have mostly been coding in Bash/Ash script. We have used tools that enable us to write GTK GUI apps in Bash, however somewhat limited. I also dabbled with other scripting languages such as Tcl/Tk and PuppyBasic.

Prior to that I programmed in assembly language for many years, and dabbled in C, C--, even Forth. One thing, I developed a dislike for the C syntax and consequently all the C-look-alikes that have spored from it. C++ even more so.

I sometimes ran into problems with the Bash scripts being a bit on the slow side, and even if they did seem fast enough I was aware that they do chew up CPU time due to the runtime interpretation. So, I wanted to move up to a compiled language, and one that made GUI programming easy. It also had to generate very small efficient executables. So started a quest that has been going on for the last couple of years.

Why not Python? In a nutshell, incredible bloat and slowness:
The slowness of Python has lead to all kinds of measures to get around it. There are so many projects to improve runtime speed, but I think that it is trying to find a solution to a problem when the problems themselves, being the runtime interpretation and lack of direct interface to C shared libraries, do not need to be there.

The argument trotted out that a virtual machine means the code can run on any operating system or CPU, is wearing a bit thin.

Why Genie?

There are some so-called Python compilers that are not really, they just package up libraries and a virtual machine into a single executable. However, there are some real Python compilers, that generate native-code executables, no virtual machine required. Two true Python-like compilers that I know of are Shed-Skin and Wirbel, however they do not create small executables -- Shed-Skin is particularly poor. The library binding bloat problem is still there too.

I was looking at another slightly-Python-lookalike compiler named Delight, which has links to other projects, among them a link to Genie. So finally, in November 2008 I found what I had been searching for, my holy grail of programming languages!

This is why I like Genie:
Although Vala and Genie are seen as languages for Gnome/GTK programming, they aren't. They are generic. They do use the Glib libraries, which provides object oriented wrappers around some lower-level functions, such as the C library, but libglib and libgobject only have libc as a dependency. The Glib libraries are in every Linux/Unix distro, so nothing extra to install -- well, that is any distro that is capable of running GTK2 applications. The generic nature of Glib means that you can use Vala/Genie for any kind of programing, but Glib/Gobject does make it particularly easy for GTK coding.

In fact, Vala/Genie does go one step further to be truly universal. The compiler has a commandline option "--profile=posix" to eliminate even the need for Glib/Gobject libraries. Some functionality is sacificed to do this, but it does mean that the powerful and easy Vala/Genie language is truly a replacement for C in areas such as embedded and boot-disk applications, and where tiny static executables are required.

Here are some code samples to illustrate. Firstly a console "Hello world":
print "Hello world"
Secondly, a GTK "Hello world" with OK button:
/* GTK+ Genie Sample Code - compile with valac --pkg gtk+-2.0 */

Gtk.init (ref args)
var test = new TestWindow ()
test.show_all ()
Gtk.main ();

class TestWindow : Window
title = "Test Window"
default_height = 250
default_width = 250
window_position = WindowPosition.CENTER
destroy += Gtk.main_quit
var button = new Button.with_label ("Click Me")
button.clicked += def (btn)
title = "Hello World"
btn.label = "Hello World"
add (button)
Note that Genie by default uses TAB characters for indenting blocks of code, however with "[indent=4]" as first line of the program, the indent can be changed to 4 spaces (or whatever is desired).

Note also that comments are as per C/C++, that is, // and /* ... */.

Why not Genie?

It can't be all good news! Here are some "disadvantages" of Genie:
Um, I can't think of anything else.

Getting started

You can go to the Vala project page and download the source, or there may be a package already available for your distro.

If you are using Puppy version 4.x, then Vala is already available in the "devx" SFS file. This is a file that provides everything needed to turn Puppy into a complete C/C++/Vala/Genie programming environment.

Read about the "devx" SFS file here:
Introduction to package management

Puppy 4.3+ has the NicoEdit text editor which has color syntax highlighting for Genie code. The Medit PET package also has Genie highlighting support.

An interesting note: NicoEdit is written in Genie, one example to show the practicality of Genie for real applications (the source is here). Created by Nicolas (forum member nikobordx)

Mime handling
Another note: I only got around to proper mime-type handling for .gs and .vala (Genie and Vala code) files after Puppy 4.3.1. But you can retrofit 4.3.1 and earlier by appending "text/x-genie:*.gs" to file /usr/share/mime/globs, and make a copy of /root/Choices/MIME-types/text_x-c named 'text_x-genie' and edit it to launch "nicoedit" instead of "defaulttexteditor".

When Vala is installed, you can compile the "Hello world" example. Just copy-and-paste the first example into a text editor (make sure that your editor is not configured to convert tabs to spaces!!!), save as '', then compile:
prompt> valac
prompt> ./hello
For the GTK "Hello world" example you need to specify the compile-time binding for the GTK libraries, like this:
prompt> valac --pkg=gtk+-2.0
If you want a quick appreciation of the supported shared libraries, look in /usr/share/vala/vapi, although these are only the official ones and there are many more third-party bindings available.

Tabs versus spaces
Another little side-note: Whether to use tabs or spaces for indentation has been the topic of (sometimes heated) discussion amongst Python coders for a long time and the general consensus is to use spaces. Jamie decided on a default of tabs for Genie, and I applaud that. Just be careful that whatever text editor is used does not convert tabs into spaces! Some links to discussion on this: 1 2 3


I have made a start with writing some tutorials. Each example given is a complete Genie application that you can compile and test:

Genie data types
Genie functions
Decisions and loops
File and console I/O
System access
Gee collection datatypes
Genie strings

More links

Some useful extra links to learn about Vala and Genie and to find out about some of the people involved and what they are doing:

Jamie's blog -- the guy who created Genie
Vala/Genie code -- lots of examples, mostly created by Nicolas (forum member nikobordx)
Vala and Genie programming -- ongoing discussion in the Puppy Forum
HOWTO: write programs -- overview of coding options for Puppy
PuppyBrowser -- internal help-page viewer in Puppy 4.3+, written by Mark (forum member MU) in Genie
ValaIDE -- Nicolas (forum member gege2061) has developed an IDE for Vala and Genie projects
Vala email-list -- developer and general discussion, includes Genie

I would like to send out a special thank you to Jamie McCracken, who created Genie, and Jürg Billeter and Raffaele Sandrini who are the main developers of Vala.
(c) Copyright 2008,2009 Barry Kauler