after about 8 years of C and bourne, i finally decided to learn a descent language. and by learn, i mean learn from the beginning, as a baby. making things clean, trying to forget crappy things i made in the past. So, i decided to choose vala for testing my fresh baby brain. This first post on vala is be the beginning of a step by step introduction to this language for people who know C or C++.
first, read This Hello World in Vala
Here is a variant, which goal is to demonstrate how to use program's arguments, and how to get an array's length:
using GLib;
public class Tutorial.CommandLineArgs : GLib.Object {
public static void main(string[] args) {
for (uint i=1; i<
args.length; i++)
stdout.printf("Hello, %s.
",args[i]);
stdout.printf("My name is %s\n",
args[0]);
}
}
Here you see the declaration of an array of strings which i called args, another declaration: an unsigned integer variable named i. Then you see the length member of the array type. Finally you see how to acces to an array's cell.
Question from the baby: how to get the real basename of args[0], having knowledge of basename() from <libgen.h> or g_path_get_basename() from GLib ? Reply: to acces g_path_get_basename() from GLib, Vala has this naming convetion: GLib.Path.get_basename(). Now it's up to you to make a better hello people program.