Defender Extension Methods -- Resolution and Invoccation

Neal Gafter neal at gafter.com
Thu Aug 5 00:01:49 PDT 2010


C# has extension methods that serve a similar purpose.  C# extension methods
are more flexible in some respects - for example, an API can be retrofitted
onto a third-party framework, or a third-party API can be retrofitted to the
LINQ pattern, using extension methods.  Extension methods are used very
widely to do the kinds of things Java does with classes such as
java.util.Collections.  Yesterday I wrote an extension method to "transpose"
(the C# equivalent of) an Iterable<Iterable<T>>, turning it into another
Iterable<Iterable<T>> whose first element gathers up all the first elements
of the input lists, and so on.  The improvement in readability is
significant.  These kinds of uses will not be possible with defender
methods.

Defender methods are more flexible in another respect - they are dynamically
dispatched and can be overridden for particular subclasses.

On Wed, Aug 4, 2010 at 10:49 PM, Paul Benedict <pbenedict at apache.org> wrote:

> Neal, does C# have something similar? I am curious with your background in
> language design, how useful or common are defender methods.
>
>
> On Wed, Aug 4, 2010 at 11:30 PM, Paulo Levi <i30817 at gmail.com> wrote:
>
>> I'd like also to ask what is the policy on defender methods from version
>> to version. Are they forever or can they be deleted from, say, the version
>> after they are introduced? I wouldn't mind to be warning to depend on the
>> default version of the defender method, if that ends up less efficient that
>> normal dispatch (the obsolescence scheme above assumes this)
>>
>
>


More information about the lambda-dev mailing list