Tuesday, November 29, 2011

Vala - Interesting hybrid language

Earlier this evening, I stumbled across an interesting programming language in development in the Linux world: Vala.


What is it?
Apparently this has been in progress since at least 2006, with syntax which builds upon that of C# (which in turn is a mix of C++ and Java). Whereas C# is practically Microsoft's programming language targeting web development (it's quite interesting how ASP.NET MVC is built on top of C# using a combination of directory structure and copious usage of annotations), Vala is closer to the Linux world's platform for developing desktop applications (like the Java+Swing combination, except with GTK+ here).

It's main selling point is that it basically compiles down to C code (as an intermediate step), whereas most of the other "modern" statically typed programming languages in the C-family with similar functionality compile to bytecode representations which can then only be run on some kind of virtual machine stack (i.e. "Common Language Runtime" or "Java Virtual Machine").

However (and this is a but), this functionality has to come from somewhere... Since this is Linux (specifically Gnome) that we're talking about, this is nothing other than the whole GLib/GObject system (akin to how Qt goes and creates its own supporting library stack and compilation types, just that the former is in C and the latter in C++ with special preprocessor markup). I've been watching this base library for a few years on and off now, and it's always been a bit of a wonder for me that no-one has made a programming language targetted to writing code for that system as its native type system. Today, this mystery has been resolved.

How does it stack up?
Like I've said, in terms of language features, it is very close C#. By and large, it could be said that it is just a clone, with perhaps a few missing things (notably LINQ, unless I just haven't come across it yet) but also a host of things which extend upon the base provided by C# in the right direction IMO. I'm also quite pleased that they have gone the way of Python, and decided to use lower_case_with_underscores as their standard naming scheme as opposed to the TitleCase format preferred by C# (personally, I found the latter style really jarring when writing code in that language, as it broke mental patterns established using every other language around, bar perhaps BASIC variants).

As far as being a C-like modern object-orientated (but not strictly so) language that compiles down to native code goes, I've been looking for something like this for ages! I'm aware that there's "D", but at least when I last checked it out, it was a bit too obscure in terms of dependent libraries (at least the GObject stuff comes in fairly standard and widely available libraries). Meanwhile, as many are quite aware, I'm not much of a fan of the vile POS that C++ is, so to have a potential option in this area is quite nice.

Speaking of ugly languages, alongside Vala there's "Genie". This is based on the same technology/backend ideas as Vala, except that it uses different syntax. While the authors of this claim that they were inspired by Python, adopting whitespace-based block syntax (as opposed to the curly-braces style), having looked at the syntax for this, IMO it lacks the visual elegance of Python. In fact, it looks quite putrid from a visual standpoint, barely rising above badly formatted Lisp, with serious legibility concerns.

Getting back to Vala. So far, I've hardly written more than a few dozen lines in this thing, so I'll reserve judgement on the quality of the programming experience for later, when I manage to spend some time hacking up something more substantial in this.

Windows Support
I'm primarily based on Windows machines (mainly for legacy reasons, although there is also the matters of some quirks and equipment related issues), so Windows support is something I'm interested in.

As of the time of writing, they do offer some Windows installers. However, from what I've found, these are at least a few versions behind in more than one way. For instance, while the current version on their site is listed as 0.14, the Windows version is still at 0.12.

However, the more troublesome part was the bundled GCC/mingw version it had. For starters, this was still using the old GCC 3.4.5 compiler (though admittedly, this was quite a good quality piece of kit which served me well for a few years). However, perhaps more troubling is that if you have an existing mingw install, you're going to end up with some path lookup issues (i.e. your standard install gets picked up first, leading to linking errors if not worse). Now, firstly I must say that I'm actually happy that their installer didn't try and clobber my existing setups on disk (like the GNU Lilypond installer did a few years ago, until I added an option which tells it not to do any of its Python-related clobbering). However, I think it's important that I bring up this issue in case anyone else runs into it while trying this out.

SO, in order to resolve linking errors such as "undefined reference to `__dyn_tls_init_callback'" when using Vala on Windows with an existing Mingw install, you need to ensure that the paths to the Vala copy of mingw libs and includes occur before their standard Mingw counterparts. That is, (assuming you've got the Vala stuff installed to D:\vala) in a batch script you run before running valac, use a line like:
@echo off
set PATH=D:\vala\bin;D:\vala\lib;D:\vala\include;%PATH%

No comments:

Post a Comment