More Readable Use Site extension Methods for java

Llewellyn Falco isidore at setgame.com
Tue Dec 7 07:42:44 PST 2010


>
>

However, we remain opposed to use-site extension methods because we believe
> that the author of an API should remain in control of their API.  Allowing
> users to monkey-patch in new functionality to existing types undermines
> this
> demarcation of responsibility.
>
> (A further problem with use-site extension methods is the lack of
> reflective
> discovery.  Consumers of classfiles (such as non-Java compilers like JRuby,
> as
> well as templating mechanism such as JSP EL) cannot easily find these
> extension methods.)
>
>
Extension methods as stated ALREADY exist. the only difference is that they
can be applied after the "." which effects readability.

Let me restate this. The only argument here is READABILITY.

i have a blog about this here:
http://llewellynfalco.blogspot.com/2010/09/extension-methods.html

These type of methods aren't actually part of the object. It is just syntax
to allow for readability. They don't give or takeaway any power from the
"creator" of the object.

As for readability, here's an example of  the difference between the current
"reverse polish" notation enforced and the ability to write after the "."

Current
dividedBy(minus(times(add(1,2)3),1)4)

Make sense?
Easy to read?

let's try after the "."

1.plus(2).times(3).minus(1).dividedBy(4)



I believe there is a strong case that is more readable.

llewellyn


More information about the lambda-dev mailing list