Re: [Vala] [RFC] Extension methods (Re: maemo5 hildon input mode)



Hello,

On Wed, February 10, 2010 16:20, Jiří Zárevúcky wrote:
Jan-Jaap van der Geer píše v St 10. 02. 2010 v 02:34 -0800:
Jan Hudec <bulb ucw cz> wrote:
This looks like another use-case for extension methods in a day.

I'd like to see them as well.

It might be useful, in some cases. It should be noted that extension
methods can only access class' public members.

Indeed. They are not really in the class, after all. Also since separate
library is supposed to be able to provide them, it does not have access
to the private members at all, since they are not exported.

I feel like we should follow C# regarding that. In C# the method must be
static and must be placed in a static class as well.

I disagree with that. The C# way feels like an ugly hack to me.
How about something like this:

public class extension Gtk.Entry {
      public void some_additional_stuff () {
              // do something
      }
}

or similarly:

public interface extension IComparable {
      public bool less_or_equal (IComparable rhs) {
              return !rhs.less_than (this);
      }
}

That's what I'd prefer too. Plus it would naturally make the C name the
same as if the method was really in the class, which I think it should.

-- 
                                        - Jan Hudec <bulb ucw cz>





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