Updated State of the Lambda

Stephen Colebourne scolebourne at joda.org
Mon Dec 12 03:21:44 PST 2011


A few odds and ends as feedback:

 Callable<Runnable> c = () -> () -> { System.out.println("hi"); };

I've always found () -> () -> in languages to be hard to grasp when
reading, and requiring of extra thought. Personally, I like syntaxes
that don't allow the above. I suspect in writing such code I will be
favouring the following instead, even if it is more verbose:

 Callable<Runnable> c = () -> { return () -> { System.out.println("hi"); } };


 int sum = list.map(e -> e.size()).reduce(0, (a, b) -> a+b);

I continue to find map/reduce examples for summing a list to be
troublesome. I remain concerned that the mental shift involved here is
being underestimated, particularly in the context of Java.
Specifically, steps that are currently performed as one, are now
having to be broken down into multiple parts - map then reduce. Note
that I do not think that individual filtering or transformation of
lists/maps will prove troublesome, my concern is primarily around
multi-step operations and reduce.

I continue to be concerned about the verbs being used and their
readability. Clearly these terms are used elsewhere, but I continue to
be of the opinion that "map" is the wrong verb for Java, because of
Java.util.Map. My preference currently remains as
"transform/Transformer". Similarly, I think "combine" may be a better
verb than "reduce". With altered verbs, I think the mental shift
required is lessened:

 int sum = list.transform(e -> e.size()).combine(0, (a, b) -> a+b);


 Arrays.sort(people, Person::compareByAge);
 Arrays.sort(people, Person#compareByAge);

I continue to strongly prefer the second syntax. The :: does not work
well for my eyes, which try to read it as a declaration:

 Arrays.sort(people, Person compareByAge);


At this point, I find the "default" keyword in default method
interfaces to be noise, and adding no value. Method bodies in
interfaces is not a complex concept, nor an unreadable one. The
default keyword makes it more complex and noisy, not less. Removing
"default" would also mean removing "default none", which again makes
perfect sense. Redclaring a method in a subinterface for documentation
purposes is rare, and for classes requires a call to super, so the
same should apply for interfaces.


Other aspects look pretty good and well-balanced to me.

Stephen


On 9 December 2011 18:28, Brian Goetz <brian.goetz at oracle.com> wrote:
> An updated State of the Lambda is available here:
>
>   http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-4.html
>
>


More information about the lambda-dev mailing list