[Vala] Feature request: cascade operator



I have been exploring and working with vala recently, so far I love it. It's
better than even a lot of the "high level" languages I've worked with. I
hope this is right place for a feature request, I couldn't find any
information on how to submit one. If people like this idea I may try to hack
it together my self, but it would obviously be much easier for the vala
developers themselves to do it, having built the whole thing and all. ;-)

The cascade operator accesses a property or invokes a method like the "."
operator, but discards the result, and returns the original receiver instead.

In brief, the cascade operator provides syntactic sugar for situations where
the receiver of a method invocation might otherwise have to be repeated.

For example, say ".." is the operator, this:

var object = new Object();
object.method_one(arg);
object.method_two(arg);
object.method_three(arg);

Can be written as this:

new Object()
..method_one(arg)
..method_two(arg)
..method_three(arg);

Another good example is object creation, here's a window being created:

var window = new Window ();
    window.title = "Hello, World!";
    window.border_width = 10;
    window.window_position = WindowPosition.CENTER;
    window.set_default_size(350, 70);

This can be simplified to:

var window = new Window ()
    ..title = "Hello, World!"
    ..border_width = 10
    ..window_position = WindowPosition.CENTER
    ..set_default_size(350, 70);

This operator, in my opinion, creates much cleaner code, and in some cases
can remove the need for additional variables.



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