Extended method reference - A proposal
Brian Goetz
brian.goetz at oracle.com
Tue May 17 21:38:44 UTC 2022
> "Having too many options for the same product is a thing, too": I agree
> with this part but we already have method references which give you another
> option to do the same thing you could have achieved via `x->y` notation.
This sounds like more of an argument *against* method references
entirely, than an argument for any particular additional ad-hoc
shorthand form. But there's a reason we have method references: they
are symbolic. A lambda encodes an arbitrary function from an ad-hoc
argument list to an imperative body; a method reference is a _symbolic
reference_ to an existing other thing; referring to things by their name
reduces cognitive load because you don't have to analyze the lambda to
see "oh, that's just delegating to method m".
> Regarding your first point, I don't consider them a "new type of
> method reference" or a "parameterised method reference". This is a
> syntax sugar to define a lambda which only calls another function.
I recommend staying away from the term "syntactic sugar"; it is almost
universally misused, and is frequently invoked to downplay the
significance of a request. This *is* a new type of method reference;
one that (a) invokes overload selection in a different way than other
method references, and (b) infers a lambda whose arity is derived from
the number of holes in the reference. That surely is a new kind of
method reference. If you're going to make a big ask, be honest about
what you're asking for.
> I agree that things like `_ < _` would be confusing and not readable
> at all. Maybe we can limit this to lambdas with only one argument?
That may eliminate certain forms of abuse, but it also makes the feature
even more limited. And, play it out: do you believe for a minute that
in the alternate universe where we had this feature, but restricted to
one hole, then there is no Mahdi-prime out there who would say "I don't
think this should be limited to one argument?"
This feature just isn't compelling. It's ad-hoc, has relatively limited
benefit, and is motivated entirely by desire to type fewer characters,
and at the same time takes a clear concept like "symbolic reference to a
method" and muddies it.
More information about the amber-dev
mailing list