Re: [Vala] Extension Methods



On Fri, 2009-03-20 at 00:09 +0100, Frederik wrote:
Feng Yu wrote:
What about this:

public extend class Gtk.Widget {
    public bool set_gl_capability (GdkGl.Config glconfig,
Gdk.GlContext? share_list, bool direct, int render_type) {

      // do stuff.
    }
}

AKA, when vala encounters the extend keyword, instead of panicing
duplicated class declarations, it simply add the decleration to the
existing class.

'extend' could be confused with subclassing (for example Java uses the
'extends' keyword for subclassing).

I know this feature from Objective C, where it's called "categories":
http://en.wikipedia.org/wiki/Objective_c#Categories

These 'categories' are even named, so you can group these additional
methods thematically. If Vala considers such a feature I would propose
the following syntax:

 public class string category SpellChecking {
     // ...
 }

 public class Gtk.Widget category GLFunctionality {
     public bool set_gl_capability (...) {
         // do stuff.
     }
     // ...
 }

These category names would get lost in C code, but they could be nice
additional information in a Vala object browser.

Yes I'm loving it. Let's file a bugzilla for it.






Regards,

Frederik
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




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