-->
Home » , , » Genie is a modern, general-purpose high-level programming language.

Genie is a modern, general-purpose high-level programming language.

genieGenie  is a new programming language, in the same vein as Vala, that allows for a more modern programming style while being able to effortlessly create and use GObjects natively.
The syntax is designed to be clean, clear and concise and is derived from numerous modern languages like Python, Boo, D language and Delphi.

Genie is very similar to Vala in functionality but differs in syntax allowing the developer to use cleaner and less code to accomplish the same task.

Like Vala, Genie has the same advantages:

    Programs written in Genie should have have similar performance and resource usage to those written directly in Vala and C

    Genie has none of the bloat and overhead that comes with many other high level languages which utilize a VM (e.g. Python, Mono, Java)

    Classes in Genie are actually GObjects so Genie can be used for creating platform code like widgets and libraries where GObjects are required for binding to other languages.
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.

Why not Python?
PythonProgrammingLanguage
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 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?
Genie_language
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.
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.

Adserver                   610x250
Here are some code samples to illustrate. Firstly a console "Hello world":
init
    print "Hello world"
Secondly, a GTK "Hello world" with OK button:
/* GTK+ Genie Sample Code - compile with valac --pkg gtk+-2.0 hello-gtk.gs */
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 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:
    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.
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.
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)
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:
prompt> valac hello.gs
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 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.
If you liked this article, subscribe to the feed by clicking the image below to keep informed about new contents of the blog:

If you liked this article, subscribe to the feed by clicking the image below to keep informed about new contents of the blog:

0 commenti:

Post a Comment

Random Posts

Recent Posts

Recent Posts Widget

Popular Posts

Labels

Archive

page counter follow us in feedly
 
Copyright © 2014 Linuxlandit & The Conqueror Penguin
-->