{"id":872,"date":"2011-01-18T08:29:57","date_gmt":"2011-01-18T08:29:57","guid":{"rendered":"http:\/\/www.mrericsir.com\/blog\/?p=872"},"modified":"2023-07-14T16:40:38","modified_gmt":"2023-07-14T16:40:38","slug":"programming-in-vala","status":"publish","type":"post","link":"https:\/\/www.mrericsir.com\/blog\/technology\/programming-in-vala\/","title":{"rendered":"Programming in Vala"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">As some of you may know, I work for an open source software non-profit called <a href=\"http:\/\/www.yorba.org\">Yorba<\/a>. Our best known product is <a href=\"http:\/\/yorba.org\/shotwell\/\">Shotwell<\/a>, a photo management application that&#8217;s similar to Picasa or iPhoto, but created for Linux. It&#8217;s the default photo app these days in both Ubuntu and Fedora.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What many of our users don&#8217;t know is we don&#8217;t develop our software in C or C++&#8230; we use Vala.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So what the hell is Vala?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The cool thing about Vala is that it&#8217;s a fully compiled, statically typed OOP language designed to be built for Gtk applications. The syntax is very similar to Java or C#, but the garbage collection is based entirely on reference counting. In other words, you get the simplicity of a modern language with the speed of a fully compiled program. Vala bindings are already available for Gtk, Gdk, GLib, Gee, and many other libraries. Or you can create your own bindings when needed by creating a Vapi file. There&#8217;s a documentation program, Valadoc, which generates pretty HTML documentation for your classes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The entire Vala package is available under an LGPL license, which is a free software\/open source license. You&#8217;ll never have to worry about Microsoft or Oracle stepping on your toes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the &#8220;Hello World&#8221; app from the <a href=\"http:\/\/live.gnome.org\/Vala\/Tutorial\">Vala tutorial<\/a>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">class Demo.HelloWorld : GLib.Object {\n    public static int main(string[] args) {\n        stdout.printf(\"Hello, World\\n\");\n        return 0;\n    }\n}<\/pre>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Save your file as hello.vala. You can compile from the command line with:<br><code>valac hello.vala<\/code><br>Now watch closely&#8230; the Vala compiler actually just creates a .c file! It&#8217;s what&#8217;s called a &#8220;source compiler&#8221; in that it converts source code from one language to source code in a different language.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, valac automatically invokes GCC to compile the .c file into an executable binary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run your demo code with:<br><code>.\/hello<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Simple, huh?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Vala syntax includes the language constructs you&#8217;d expect in 2011, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>interfaces<\/li>\n\n\n\n<li>single inheritance<\/li>\n\n\n\n<li>non-nullable variables<\/li>\n\n\n\n<li>foreach loops<\/li>\n\n\n\n<li>delegates<\/li>\n\n\n\n<li>signals<\/li>\n\n\n\n<li>reflection<\/li>\n\n\n\n<li>built-in multidimensional arrays<\/li>\n\n\n\n<li>type inference<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">There&#8217;s plenty more sample code and tutorials on <a href=\"http:\/\/live.gnome.org\/Vala\/Documentation\">Gnome&#8217;s Vala site<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Documentation for some of the most common library bindings is available at <a href=\"http:\/\/valadoc.org\/\">Valadoc.org<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, ready for the bad news? Despite being a relatively feature-complete language, there&#8217;s really no perfect IDE for Vala yet. If you&#8217;re used to powerful graphical debuggers, class browsers, and jumping around the code like in Eclipse and Visual Studio, you&#8217;re out of luck.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The only Vala IDEs at the moment are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MonoDevelop: A great start, but for the features it&#8217;s rather heavy.<\/li>\n\n\n\n<li>Valide: I was never able to get this one to even compile! But the screenshots look promising.<\/li>\n\n\n\n<li>Valencia: This is Yorba&#8217;s GEdit plugin, which provides only barebones Vala functionality on top of GEdit, including jump to definition and autocomplete.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So there you go, that&#8217;s Vala. It&#8217;s still a young language, but it takes away the headaches of developing Gtk apps in C, and it doesn&#8217;t have the uncomfortable legacies of C++. Give it a shot!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As some of you may know, I work for an open source software non-profit called Yorba. Our best known product is Shotwell, a photo management [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","slim_seo":{"title":"Programming in Vala - MrEricSir.com","description":"As some of you may know, I work for an open source software non-profit called Yorba . Our best known product is Shotwell , a photo management application that's"},"autoblue_enabled":true,"autoblue_custom_message":"","autoblue_shares":[],"autoblue_post_url":"","autoblue_publish_document":false,"footnotes":""},"categories":[3],"tags":[99,29,363],"class_list":["post-872","post","type-post","status-publish","format-standard","hentry","category-technology","tag-linux","tag-programming","tag-vala"],"_links":{"self":[{"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/posts\/872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/comments?post=872"}],"version-history":[{"count":8,"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/posts\/872\/revisions"}],"predecessor-version":[{"id":10397,"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/posts\/872\/revisions\/10397"}],"wp:attachment":[{"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/media?parent=872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/categories?post=872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mrericsir.com\/blog\/wp-json\/wp\/v2\/tags?post=872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}