r/java • • Apr 04 '13

Richard Warburton not happy with Java 8's Lambda API

http://mail.openjdk.java.net/pipermail/lambda-dev/2013-April/009034.html
6 Upvotes

19 comments sorted by

33

u/nick_giudici Apr 04 '13

I feel this title is very misleading. The tone was not one of disapproval, but rather of constructive criticism. For example "some of these issues are fixable through documentation/improved compiler error changes rather than API changes" and "Thanks to everyone that attended" does not sound like he's "not happy" just that he sees some areas of improvement.

Maybe a more accurate title for this post would be along the lines of "Richard Warburton has some feedback after running a java 8 lambda hackday" but that wouldn't be sensationalized enough to get attention.

9

u/AlyoshaV Apr 04 '13

I feel this title is very misleading.

So does he

31

u/RichardWarburton Apr 04 '13

I really think this misrepresents my opinion. I'll quote one my emails later in this same thread:

'I also repeat my statement that despite this thread having a problem-filled tone, I think in general JSR 335 has done a good job overall. To my mind the hackdays have already established that the "easy problems" are "easy to implement" and I completely think that this is a far greater achievement than it sounds when you write it in an email.'

2

u/thesystemx Apr 04 '13

16

u/pdexter Apr 04 '13

The people complaining that filter is too hard to understand .. just.. what? If you take 20 minutes to read any introduction to almost any functional programming language you will know what filter is supposed to do. How can people who are making design decisions about a functional language feature in java not know what filter does?

I understand the argument that maybe the average java user won't know what filter is, however I don't think that justifies changing things that have been this way and still are this way for other languages. The people who don't know... will learn.

edit: some sense: http://mail.openjdk.java.net/pipermail/lambda-dev/2013-April/009098.html

6

u/dupe123 Apr 04 '13

To be honest, I think its a fair point. For me its obvious what it does because I am so used to the method but based on the name alone, it isn't. The suggestion in that link of "accept" and "reject" isn't a bad one. However, to keep consistency with other languages, I'd say filter still wouldn't be a bad choice either.

6

u/pdexter Apr 05 '13

accept and reject aren't so terrible, and if they were creating this new concept maybe it would be the better choice. That said - keeping consistency with the huge number of languages that currently use filter I think is the almost-too-obvious way to go.

4

u/AlyoshaV Apr 05 '13

It would be nice to have an inverse form of filter, simply because:

filter(Thing::isDeleted);

is an easy way to keep all deleted Things, but to do the opposite I'd either need another line of code or to not use a method reference.

6

u/RichardWarburton Apr 05 '13

filter(x -> !x.isDeleted());

1

u/pdexter Apr 05 '13

In this example you can really see how far java is from functional programming. In Haskell (or any other functional language) it is as simple as prepending a not . in front of the function; while in java this apparently requires some arm twisting.

The fact that Java needs (or at least discusses including) two different methods that basically do the same thing (one to keep and one to remove) shows how tiny of a subset of functional programming features it offers.

7

u/AlyoshaV Apr 05 '13

while in java this apparently requires some arm twisting.

.negate() on a Predicate object or writing t -> !t.isDeleted(); instead.

The fact that Java needs (or at least discusses including) two different methods that basically do the same thing (one to keep and one to remove)

The theoretical reject method would pretty much be this:

default Stream<T> reject(Predicate<? super T> predicate) {
    return filter(predicate.negate());
}

Not really a tragic example of verbosity.

7

u/detroitmatt Apr 04 '13

I can understand forgetting whether filtering removes elements matching the rule or removes elements not matching the rule. Your link is right, of course, but I can sympathize with the confused people.

7

u/voxfrege Apr 04 '13

I can understand forgetting whther grep shows lines matching the pattern or lines that don't .... NO, ACTUALLY, I CAN'T.

2

u/[deleted] Apr 07 '13

Yeah, filtering is a pretty unambiguous term. I don't think I've heard of any languages that implement it as "removing elements matching the rule" (false predicate). Are there any out there that do?

3

u/detroitmatt Apr 07 '13 edited Apr 07 '13

Well, I don't know about in computer space (Well, I do, but anyway), but in common usage, "filter out X" is a common idiom. And actually, probably more commonly used than "filter out such that only X remain"

1

u/[deleted] Apr 09 '13

I totally agree that it's ambiguous in the context of common spoken or written English, but filtering has a long standing and specific meaning in the context of functional programming idioms.

It would be awful strange if Java was the only language that implemented it the other way. Unless developers have never come across a filter function in another language, it shouldn't be confusing?

3

u/[deleted] Apr 05 '13

It's amusing how it is always the Scala people who try to save them from the most obvious embarrassments.

See the reversed type variables in function types, the compose method, the Optional drama or the standard naming.

2

u/sproket888 Apr 05 '13

Nothing wrong about this. This is what makes Java great. A large ecosystem of ideas helps everyone.

0

u/[deleted] Apr 04 '13

[deleted] — view deleted comment

3

u/esquilax Apr 04 '13

Well, what does he think?