new keyword 'extension' really necessary?
Gernot Neppert
mcnepp02 at googlemail.com
Fri Aug 6 09:10:47 PDT 2010
Osvaldo Doederlein schrieb:
> 2010/8/5 Rémi Forax <forax at univ-mlv.fr>:
>
>> Le 05/08/2010 20:25, Osvaldo Doederlein a écrit :
>>
>>> Extension methods are not allowed inside annotations, so I guess the
>>> implementation and spec issues are at least less severe, as
>>> disambiguation is trivial by the outer context being an annotation or
>>> not. Maybe it can't be completely handled by (simple) grammar changes,
>>> but that would be about it (it seems; correct me if that's wrong).
>>>
>> In fact, there is no 'grammar' problem.
>> The local keyword 'extension' avoid to change too much the javac parser,
>> a hand written top-down recursive parser.
>>
>> But the real value is, as Brian says, that an extension method
>> is tagged with the local keyword 'extension'.
>> Easy to explain, easy to grasp.
>>
>
> You imply that without 'extension', the syntax is hard to explain,
> hard to grasp. This is where I disagree. This verbose, DRY-violation
> syntax won't buy anything; 'default' is perfectly fine, I don't think
> programmers will be confused. Notice also that you assume that
> programmers want to make the association between the syntax and the
> feature name "extension method", but this name is just a convention
> and in some degree arbitrary - we could decide to use "defender
> method", or maybe even "default method" [in that case the 'default' is
> certainly sufficient ;-) ]
>
I think you have a good point here:
the experts who came up with the idea of 'extension' have a certain
perception of this new feature:
For them, it shall only ever be used by so-called 'library developers'
who will responsibly evolve existing interfaces.
It seems they want to make sure that this view of theirs is somehow
conveyed by the syntax.
IMHO, that is a futile endeavour. People will use the new feature for
whatever purpose comes to their minds. There will be no restriction to
evolving Standard JDK interfaces.
Technically, the new keyword 'extension' does not much sense. You can
design an interface from scratch and make all methods 'extension
methods' right from the beginning, e.g. for the sake of easier
implementation by clients. Then, nothing is being 'extended'...
More information about the lambda-dev
mailing list