SIGN UP MEMBER LOGIN:    
ARTICLE

Anyone for VALA?

Posted by Vulpes Articles | Current Affairs March 09, 2011
Vala is a new programming language based on C# syntax which compiles to C code rather than Common Intermediate language.
Reader Level:

What's Vala?

Vala is a new programming language based on C# syntax which compiles to C code rather than Common Intermediate language. Consequently, when the C code is compiled, its performance is comparable to that of a 'normal' C application rather than that of .NET or Mono.

Vala is open source software which is being developed as part of the GNOME platform and has not yet reached version 1.0. The latest version (as I write this) is 0.11.6.

It uses the GObject and GLib libraries and is therefore an alternative to languages such as C++ or Objective C for adding object oriented extensions to the C language.

How does it differ from C#?

The main differences are as follows:
  1. Instead of garbage collection, Vala uses 'reference counting' which is the same system as COM. This means that a count is kept of all the references to an object and, when this count reaches zero, the object is destroyed. To avoid reference cycles, weak references can be used. It's also possible to destroy objects deterministically by calling the class's destructor.
  2. Vala uses 'checked exceptions' which is the same approach as Java. This means that a method has to declare all the possible exceptions which it can throw.
  3. Vala does not support method overloading. This is for compatibility with C which doesn't have this feature either. In practice, this is not as onerous as it sounds because Vala does support optional arguments.
  4. Interfaces in Vala can contain non-abstract methods and private methods which enables you to create 'mixins'.
  5. As in Java, enums in Vala can have methods and not just constants.
  6. Method parameters and return types in Vala are non-nullable by default. So, if you have a variable of type Foo, then it can never be null but a variable of type Foo? can be. This means that you don't usually need to check for null return values.
  7. Automatic properties in Vala can have a default value as part of their declaration.
  8. Methods in Vala support 'ensures' and 'requires' clauses for argument and return value checking. In C# you can do something similar using Code Contracts rather than as a built in language feature.
  9. Pointers can be used anywhere in Vala. In C# they can only be used in 'unsafe' blocks.
  10. As in C, there's no bounds checking for Vala arrays. In C# bounds checking can only be circumvented by using unsafe code. 
  11. Generics in Vala do not support constraints.
  12. Surprisingly, Vala already has support for asynchronous calls (using the async/yield keywords) which is planned for C# 5.0 (using the async/await keywords).
  13. Vala doesn't support LINQ or extension methods.
  14. There's no operator overloading in Vala.
  15. Methods in Vala can be global - unlike C#, they don't have to be declared inside classes or structs.
  16. Vala strings use UTF-8 encoding rather than Unicode.
Does Vala only work on Linux or other Unix based systems?

No, it will work on Windows as well.

To develop Vala applications you can either use MonoDevelop (Mono's IDE), Val(a)IDE  which is an IDE written in Vala itself or a text editor and the command line.

How do you write 'Hello World' in Vala?

As a slight departure from the norm, we'll write C# Corner, with alternative letters separated by spaces, to the console:

void main()
{
      string s = "C# Corner";
      PrintWithSpaces(s);
}

void PrintWithSpaces(string s)
{
      for(int i = 0; i < s.length; i++)
      {
         stdout.printf("%c ", s[i]);
      }  
}

If you're developing from the command line, you'd save this file as ccc.vala and then compile it with:

     valac ccc.vala

Notice that this not only invokes the Vala to C compiler but the C to native code compiler as well to produce ccc.exe

To run it simply type:

    ccc   

Where can I find more details?

Check out the Vala pages at GNOME (http://live.gnome.org/Vala) which, as well as documentation, contains links to download the latest version.

As Vala is still being developed, the information in this article may change before the final release.

Login to add your contents and source code to this article
share this article :
post comment
 

One more new thing to learn

Posted by Shalini Juneja Aug 02, 2011

It's being developed by Jürg Billeter and Raffaele Sandrini. I think the purpose is to give the GNOME developers a modern object oriented version of C with as little extra overhead as possible, bearing in mind that C++ isn't one of their 'official' languages. Although the language isn't yet finished, early indications are that performance will be good - see http://code.google.com/p/vala-benchmarks/wiki/BenchResults.

Posted by Vulpes Mar 09, 2011

Interesting! Who is developing Vala and what's the purpose?

Posted by Mahesh Chand Mar 09, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor