Extension vs defender methods

Robert Field Robert.Field at oracle.com
Mon Nov 14 19:48:09 PST 2011


I agree. "extension" and "defender" reference use, not mechanism, and 
thus are probably not the best long-term names.

Context/timing is important here.  This mechanism is tied to lambda 
expressions because, without it, the libraries could not be reasonably 
extended to use lambda -- weakening the whole motivational chain.  So, 
this mechanism is part of the lambda project.  And, as such, they are 
"extension" methods.

Five years from now, the relationship between lambda and this mechanism 
will be nothing but a historical footnote.  Extending existing 
interfaces will still be an important use-case, but not the only one.

On one point I disagree, this mechanism will need to be discussed -- so, 
it needs a name.  Take this email as proof, "this mechanism" doesn't 
really cut it.  Indeed, such a name might not need to appear in spec.  
If such methods are prefaced with "default", as is the current plan, 
then "default method" seems the logical choice.

But, really, as long as we can agree that the name isn't set in stone, 
the more substantial issues and even the superficial syntactic issues 
can, and should, be nailed down first.  These will then inform the 
momentous decision about what to call them.

-Robert


On 11/13/11 4:19 PM, David Holmes wrote:
> I think there is confusion about what is being added to the language
> versus the main use-cases for that thing.
>
> "extension methods" comes from the ability to extend an existing
> interface in a source and binary compatible way with existing clients of
> that interface.
>
> "defender methods" (previously 'miranda methods') comes from the same
> use-case but uses the quaint analogy to the legal system where if you
> don't have your own [lawyer|implementation] one will be provided for you.
>
> The mechanism itself is neither of these things.
>
> What is being added is a way to provide a default implementation for a
> method declared in an interface. It doesn't matter if that is a new
> method being added to the interface, or an existing method being
> updated, or whether the interface itself is being defined for the first
> time.
>
> So while it has been somewhat useful to refer to "extension methods" and
> "defender methods" for the purposes of example and discussion I don't
> think this needs to be carried forward. There is no reason to give
> methods that have default implementations a special name - they are just
> regular interface methods for which a default implementation has been
> specified.
>
> My 2c.
>
> David Holmes
>



More information about the lambda-dev mailing list