Re: [Vala] Feature request: cascade operator



On Wed, 2013-11-20 at 00:53 +0000, Christian Johnson wrote:
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.

The bug tracker is the right place for feature requests.  Here is the
bug for what you're requesting:

        https://bugzilla.gnome.org/show_bug.cgi?id=686562

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. ;-)

This is something that Jürg would have to sign off on, but I don't think
he would have any objection.

It would be easier, but there is no guarantee that it will happen.  The
most reliable way to get improvements made to open source software is to
submit a patch.  And, of course, every time you write a patch you become
more familiar with the code base so it's easier to make other
improvements in the future.

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.

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

Attachment: signature.asc
Description: This is a digitally signed message part



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