Default print behaviour / function for non-string variables
It seems like everytime you want to print an array or some non-string / complex variable, you have to write your own utilities to do so e.g for an array:
double[] arr = { 5.0, 3.4, 9.1 };
print ("{ ");
foreach (double n in arr) {
print (arr.to_string () + " ");
}
print ("}\n");
And some more:
int a = 10;
float b = 20.0f;
string[] arr = { "x", "y", "z" };
Object object = new Object ();
// Cannot print arr trivially here without constructing another string
print (@"$a $b [$(object.get_type ().name()) at %p]\n", object);
I think Vala could introduce a new function / built-in that allows to print a basic human-readable representation of any type e.g: printany (a, b, arr, object)
which would by default print all these objects separated by space and ended by a new-line:
// Prints "10 20.0 { "x", "y", "z" } [GObject at 0x55c7b8573a00]"
printany (a, b, arr, object);
Arbitrary objects could be handled like above e.g printing an Object
would yield [GObject at 0x55c7b8573a00]
.
This would be helpful in situations where you want to print / debug something very quickly without writing additional helpers.
Edited by Ghost User