Re: [Vala] Vala wishlist



'to_string' hack exists :

int number = 33;
print (@"$number");

Gee.Traversable supports 'fold' and other few functions :
http://valadoc.org/#!api=gee-0.8/Gee.Traversable

2016-01-12 22:54 GMT+01:00 Afonso <afonsojoao96 gmail com>:

My thoughs about Vala
=====================

I just started coding in Vala, and i found it's a quite fun language
to learn, very simillar to Java and C#. The integration with GLib and
GObject is simply amazing, and the possibilty to generate C code is
also very pleasant.

As `Vala` is still in a development phase, I would like to suggest
a few features that could help `Vala` reach the next big step.


# More functional support

Altough `Vala` has support for closures, it would be good to hava even
more functional power.

For example, `Vala` could ship with a `filter` function that supports
every Gee Collection, something like:

var books = new TreeSet<Book> ();
books_from_year = books.filter ( (b) => { return year == 1952; });

Other functions could behave the same way, like `map`, `reverse`,
`folds`, `all`, `any`, `or`, `all`, `takeWhile`, `dropWhile` just to
mention a few (i know, i know, Vala != Haskell xD).

Also, most closures end with a return statement. It would be a lot
cleaner if one could skip the `return` statement, for example:

var f = (a) => { a == 2; }; // Instead of { return a == 2; }

It does much more sense in a closure context not to have a return
statement. Also with mutliple statements closures, `Vala` could behave
a little bit like `Ruby`, and automatically infer what does the
closure returns:

var f = ( a, b ) => {
 a = b - 1;
 if ( a > b )
  "ok"; // return "ok";
 else
  "not ok"; // return "not ok";
};


# More syntatic sugar for print

Whenever `stdout.printf` or `print` are invoked with an object,
automatically use `to_string ()` method (like `Java`).
For example, suppose we have the following class definition:

public class Book : Object {
 public string title { get; set; }
 public int year { get; set; }

 public string to_string () {
  return "Title: %s, Year: %d".printf(this.title, this.year);
 }
}

It would be nice if we could simply print an object like this:

void main (string[] args) {
 Book b = new Book ("The Old Man and the Sea", 1952);
 print (b); // <=> print (b.to_string());

 /* Output:
 >> Title: The Old Man and the Sea, Year: 1952
 */
}


Automatic array printing for basic types (and objects - using
`to_string ()` method), like so:

 void main (string[] args) {
  string[] authors = { "George Orwell", "John Steinbeck" };
  int[] years = { 1999, 2000, 2001 };

 Book b1 = new Book ("The Old Man and the Sea", 1952);
 Book b2 = new Book ("The Pearl", 1973);

 Book[] books = { b1, b2 };

  print (authors);
  print (years);
  print (books);

  /* Output:
  >> ["George Orwell", "John Steinbeck"]
  >> [1999, 2000, 2001]
  >> [Title: The Old Man and the Sea, Year: 1952,
      Title: The Pearl, Year: 1973]
  */

 }

Wish you all the best regards

3º ano, Mestrado Integrado em Engenharia Informática,
Universidade do Minho

_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]