Streams

Sam Pullara sam at sampullara.com
Fri Sep 14 00:23:06 PDT 2012


On Fri, Sep 14, 2012 at 12:13 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>> 2) Optional should implement more of the Stream API like flatMap and
>> some others.
>
> Is there a document somewhere that explain the pro and cons of using
> Optional ?
> Currently I see it as a way to add a level of indirection with no real
> benefit,
> the VM currently optimizes code that check a variable is null if the
> variable is never null,
> so this kind of nullcheck are free. With Optional you add a level of
> indirection in any case
> (null or not null) and you have an allocation if you're not lucky and the
> escape analysis doesn't work.

There is a performance cost, but it looks nicer than null checks and
works when null is a real answer. They are very commonly used on the
Scala side of things and clean up a lot of code. It would be nice if
it was natively supported by the VM though. Here is a blog post on
using them in Scala:

http://www.codecommit.com/blog/scala/the-option-pattern

I just find it much more natural versus an exception or null check.

>>
>> 3) I really, really believe that we should have something around
>> Future like I have prototyped here:
>>
>> https://github.com/spullara/java-future-jdk8/blob/master/src/main/java/spullara/util/concurrent/Promise.java
>>
>> Blocking to get the result of a Future is a bad code smell in my mind
>> after using Promises for a long time at Twitter. This will be a great
>> opportunity to get all the APIs in line with a much better way of
>> handling asynchronous work that isn't CPU bound.
>
> Sam,
> I fully agree, and think you should move this question to
> concurrency-interest mailing list
> at least to have Doug comments on this idea.

I think when he saw it last he said something like it doesn't look
very Java like. I'll post it anyway. It dovetails nicely with the
collections API as well, using many of the same verbs.

Sam

>
>
> Rémi
>


More information about the lambda-spec-experts mailing list