![]() |
The Genie language
|
There is not yet an official logo for Genie/Vala, above image is a contender, created by Wolter Hellmund.
NOTICE These Genie/Vala pages are no longer being updated, as I have defected. I have found BaCon to be more suited to my purposes: http://bkhome.org/bacon/ |
Introduction
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:
- Slow
A runtime interpreted language is inherently slow, even if compiled to bytecode. Python, Perl, Tcl, Java, PHP and applications that require mono/.net are all in this category. - Bloat
The overhead that Python needs is incredible. A Linux system has a whole lot of shared libraries, just look in /usr/lib, but Python is unable to use them directly and requires a huge amount of binding layers. Not only does that add bloat but it also slows down execution.
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:
- A true compiler
A "Hello world" console executable is 2.9KB, a GTK GUI "Hello world", with a OK button thrown in, is 5.8KB. I even created a completely static console "Hello world" with Dietlibc, only 2.1KB! - Easy Python-like language
Say no more!
- Easy GTK programming
Avoid a lot of the cryptic low-level messy details.
- Link directly with the system shared libraries
No huge binding libraries, nothing required at runtime. No bloat! - Library support
Compile-time bindings available for most shared libraries. - Plain-C intermediate code
Only needs Gnu C compiler -- so can be compiled for any operating system and CPU. - Object oriented
Objects are not "bolted on" as for some languages that started life as procedural-only. But Genie code can be as non-object-oriented as you wish.
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":
initSecondly, a GTK "Hello world" with OK button:
print "Hello world"
/* GTK+ Genie Sample Code - compile with valac --pkg gtk+-2.0 hello-gtk.gs */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).
uses
Gtk
init
Gtk.init (ref args)
var test = new TestWindow ()
test.show_all ()
Gtk.main ();
class TestWindow : Window
init
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 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:- Static type handling
As opposed to Python's dynamic type handling. Whether you see this as a disadvantage depends on your point of view -- arguably static type handling is better! Note, Vala/Genie has "type inference" which is a way of avoiding specific type declarations -- but, I hasten to add, that is only a convenience to the coder and data types are still static.
- Compiled executable
As opposed to having a script that is easy for anyone to see and edit in the target distro. But, I suppose you could ship the binary package with the source files included, then as long as the development tools are installed anyone can do a quick edit-compile to make changes, at least for simple cases where the application source is one file. - No run-time source-code evaluation
Yeah, this is a nice feature of run-time interpreted execution. This is a convenience that has to be sacrificed with a compiled program. One tick for Python.
- Not much documentation
Well, there is a lot, but much of it brief and/or cryptic. Not so good for learning.
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:
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.
NicoEdit
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)
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
'hello.gs', then
compile: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".
prompt> valac hello.gsFor the GTK "Hello world" example you need to specify the compile-time binding for the GTK libraries, like this:
prompt> ./hello
prompt> valac --pkg=gtk+-2.0 hello-gtk.gs
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
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
Tutorials
I have made a start with writing some tutorials. Each example given is a complete Genie application that you can compile and test:IMPORTANT NOTICE: THESE ARE A WORK IN PROGRESS!
Genie data types
Genie functions
Decisions and loops
File and console I/O
System access
Gee collection datatypes
Genie strings
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
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
Acknowledgements 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. |