Vala is Awesome

December 11th, 2008

The GUI Dilemma

Linux has many language implementations but I keep finding myself driven to C by quality documentation and faithful implementations. Python, Ruby, and Scheme are all great but docs for bindings are second-hand and I usually need to pull out the original library reference or look at C headers and test-cases to accomplish anything.

If I want to port to the maemo platform I have to port the bindings too. Just more version hell.

On top of that there is interpreter lock with internal threads and that isn't good for the GUI. Loading a GtkListStore is already slow enough when calling from C but doing it in an interpreted language means an inner loop with additional marshaling. Database extensions should also be written as efficiently as possible because that makes them more flexible as I don't have to tiptoe around them in SQL; worrying whether my slowness is getting called 10 or 10e6 times per query. Then there's callbacks, like for sorting, which are called nlogn times or worse. If I'm writing asynchronous IO, ListModel loading, database extensions, and sort callbacks in C then there's very little left to do in an interpreted HLL.

I hate GObject C but I like GObject enough to wish I had used it for some things that are slowly turning into their own private spaghetti hell. Refactoring creates even more opportunities for error and is time consuming. C is hard, let's go shopping :)

C++ would be a good option if I had a much higher IQ. I can use existing classes but writing a new class without memory leaks, using it properly with exceptions, and looking out for excessive copying is a mental exercise in itself. That's actually a languages strength, lots of meaning in a line, but it's not an abstraction as much as it is a complex macro expansion. It's a fun language but it doesn't offer the blissful ignorance I often want.

Introducing Vala

With Vala the blissful ignorance is there for the taking, up to a point of course. It is a modern but slightly crippled language that steals as much as possible from C#. It has all the OO features of GObject, including singe inheritance, multiple interfaces, runtime binding, and dynamic properties. Destructors and constructors are supported along with private/protected/public members. There is also a limited "compact" class that avoids GObject for better performance. Structs and types built on machine words like int, float, and bool do not have OO features and have an exact correspondence to C. There is a string type built on GString that supports some useful operators like + and +=. Type inference means variables can be declared simply with the "var" keyword. The type-system also differentiates between nullable and non-nullable types and checks GError exceptions at runtime. Garbage collection is accomplished via reference counting, which is good enough for most things. Vala supports generics with the familiar template-like syntax. All generics appear to be implemented with gpointer, i.e. (void *), instead of creating new code and structures for each instantiated type. For example a Point2<int> p = {1,2} would create a struct containing two gpointers. Function delegates can be defined inline and look like a lambda. Currently, only formal parameters of the lambda may appear in the body. Vala accepts full lexical closures syntactically but the generated C contains undeclared identifiers and does not compile. Vala will most likely implement ref-counted closures in the future via GClosure, or so I hope.

The language compiles through C and anyone familiar with GObject should be able to read the C output to easily figure out what's going on. I wouldn't hesitate to use a Vala library from C because it's really just GObject under the hood. Bindings are easily implemented in a separate "vapi" file. There is no documentation for vapi at the moment but it really doesn't need much. Marshaling is delegated to GObject at runtime and calling GObject code from Vala doesn't cost any more than calling from C. The whole language is actually syntax sugar for C. It's C++ reinvented with the benefit of C# and Java in the rear-view mirror.

GObject has a high runtime cost but the Vala designers have created some very useful pockets in the type system to mitigate that issue. Vtable lookup always occurs for interface methods, unfortunately even when the concrete type is known at compile time. Inherited methods are called statically through upcasting so better performance is possible by restricting OO usage to compact classes and inheritance-only method resolution. The pointer overhead in generic structures would probably offset any performance increase from static method binding unless it is used carefully. Unrestricted use of generics would imply using them in interface constraints and those entail virtual method calls anyway. The language also doesn't leverage stack allocation for objects like C++ so instantiation requires heap allocation. Structs have access-controlled members and are normally stack allocated but copy constructors and destructors are still generated for structs to support full-object members. The compiler currently accepts inheritance and interface syntax for struct declarations but ignores it when generating code.

The roadmap is set for a 1.0 release in March 2009; fingers crossed. Vala is promising because it's conceptually simple, as portable as glib, has decent performance, and plays well with C in both directions.

PS. I should warn the reader that I just discovered Vala yesterday and my knowledge of it is limited to examining the C output of the version 0.5.2 compiler. Some of this info is probably wrong so this article is As-Is, No Warranty. However, I'd appreciate a comment if I failed to understand something about Vala.

Vala Documentation (draft)

Vala Tutorial

Speed Shootout

14 Responses Follows

  1. T says

    Vala sounds like a fancy designer purse :)

  2. Yu says

    There is a string type built on GString that supports some useful operators like + and +=. This is not the case. You use StringBuilder for GString. + and += are based on strcpy stuff.

    Otherwise it is a very good article. You observed more in one day than I did in months!

  3. Carlos Costa says

    I recently discover Vala and like it, mostly because Vala generate C code to be use with GObject, a really fast combination. Some things to be considered (you mentioned some of then): - C# with Mono is bigger and slow - Java has profiling to run fast, but the jdk is memory consumer - C++ with gcc is cool, but you need to deal with memory leak - Python, Perl or Ruby are interpreted and slow for big projects

    I’m studying Vala, discovering the language and the environment. This comment is just to share with you a link I recently discover (if you don’t know yet):

    http://www.valadoc.org/

    Thanks, Carlos.

  4. Arkadi says

    Great review! I’m studying VALA, and writing my own small program with it: https://launchpad.net/repositor I think this programing language has a real bright future on Linux and telling all my friends about it :)

  5. rqweqwre says

    Really like your blog,thanks for sharing it with us.And I also llike 49ers jerseys.Despite your Super Bowl has ended, the Seattle Seahawks Jerseys article off calendar year auction can completely however accelerate your admirers and aswell accompany beatitude that will them. As we could see that you will discover multitudes of NFL jerseys of Reebok during the industry. The NFL will admission a 10-12 months absolute authorization to Reebok alpha during the 2002 NFL division to accomplish and promote NFL accountant merchandise, together with jerseys, amusement apparel, cossack and an NFL-branded accoutrement line. The acceding aswell offers Reebok absolute rights to advance a fresh band of NFL exercising devices. The 49ers jerseys aswell has the edge to entry an disinterestedness situation during the new small business.

  6. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like beats by dr dre. Monster hammers headphones is so accustomed in accompany offworld,beats by dr dre, it truly is abreast at audio followers for audio fanatics, what is more, it is acclimatized devising to buck your admired audio with antic accurateness and acclimatized audio. Get an accessory with the photo, you appetite applause it,beats by dr dre studio, having an ambrosial bloom training course,monster beats flat the Monster Beats abandoned has afflicted a allocation in the boyish ladies. The acceding a affiliate of Monster, Lady Gaga, and red-colored was show up afore these days.The Monster Beats Solo Acclimatized Version essentially appears absolute apparent, and is also no which the adapt individuality that youngster peoples ambition?

  7. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like beats by dr dre.If you are a songs fanatic admiring to apprehend your admired music most effective durations of time,beats by dr dre outfits you entirely properly. They take been meant to complete assertive a blood-tingling music ability for continued intervals without any causing affliction or conceivably affliction on the personal. A alluring ideal through the monster Bests is you put on take to assignment down into your wallet to monster abeyance or media mute. A rapid faucet into is the affair that it takes to complete the needful. You’ll be able to baddest from a arrangement of clear equipment to evaluation these monster earphones. Browse the net in your case to cross a alluring arrangement of admirable components around the internet.These are provided in awfully huge discounts.

  8. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like beats by dr dre.It can motion you the lightest fat as able-bodied because the admirable overall look. In the three areas of your architecture will allow the abandoned fits in the bunched accustomed situation. With Beats abandoned to acquaintance admirable songs has never been so straightforward. Administration Discussion: The ear plugs can complete abiding you feel well. Expend time over the proper beats by dr dre for auction to apprehend not alone new music to obtain additional acceptable alfresco sounds, but aswell accord on your own the affluent full you’d like. Splendidly acceptable for all kinds of gamers. Which has a prime ascendancy accidentally say pictures for that headphone cable Dre, you yield ascendancy of your accountable has moved. New aperture beatific additional than a actor gallons of oil into your river Kalamazoo, claimed Wednesday, letters AFP reported. The Environmental Protection (EPA) mentioned which the aperture commenced Monday, if the pipes accessibility from the Marshall Michigan, and spits on oil monster beats affordable. All within the abundance can be exhausted for quite a few hours.

  9. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like

    beats by dr dre

    .Is dollars accrued for you? Any individual may say “yes”. Within their thoughts, they can not abide afterwards dollars and capital of beforehand is accrued for them. They get they’re able to blot money to acquire gathered they allegation and want, spending it to order a abounding residence, a admirable garments, affluence purses, big-ticket makeup, a complete vehicle, activated beautification and much of casting items, including the angel acclaimed headsets of beats by dr dre, acclaimed watch-Rolex and many others. In acclimation to admission as abounding funds as possible, these receiving might beats headphones rob through the flush particular person, abduct a bazaar during the night, barefaced any one for capital or maybe accessory an aged man only for accepting tons of money for affluence items. A number of canicule in the past, I abutting my colleague’s alliance ceremony. The guy who she affiliated are sixty now accepting 3 sons and a woman. I used to be abashed afresh , brainwork what can make a 20 a long time previous admirable bairn ambition to accessory such a previous and beastly guy. Is it the authentic applause amidst them? I apprehension to get a linked time but however obtained no response. Afresh my accession abettor abreast to me “she you should not applause that person whatsoever, what she applause is his income. That aged man obtain added than 1million RMB. “Oh, my god, I am unable to purchase my ears. Afresh I get to amass that these receiving who forward funds is extra significant than abolishment away , such as their bodies, their soul. Will lose theirselves for money at last. How addled and inadequate they can be.

  10. Lloyd says

    I’m considering using this with Puppy Linux (Saluki). I’ve used C/C++ for years, but I like the elegance of Vala. It’s refreshing. I only wish there were better documentation. Perhaps that will come in the future, although by now (2012) you’d think it’d have arrived. Better documentation may have driven this language more. Enjoyed your observations…

  11. bad company 2 vip code xbox 360 says

    Hello there! I could have sworn I’ve been to this website before but after going through many of the posts I realized it’s new to me. Regardless, I’m certainly happy I discovered it and I’ll be bookmarking it and checking back frequently!

  12. windows 8 upgrade from xp says

    Greetings I am so grateful I found your blog, I really found you by mistake, while I was researching on Google for something else, Regardless I am here now and would just like to say thanks for a fantastic post and a all round entertaining blog (I also love the theme/design), I don’t have time to go through it all at the minute but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the superb job.

  13. west palm beach movers says

    It’s actually very complex in this full of activity life to listen news on Television, so I simply use the web for that reason, and get the most recent information.

  14. automatic knife says

    My brother suggested I might like this website. He was totally right. This post truly made my day. You cann’t imagine just how much time I had spent for this information! Thanks!


Your Response