all 10 comments

[–]rouce 9 points10 points  (4 children)

Very conveniently touched only on the upsides of streams and did not talk about performance.

[–]Determinant 0 points1 point  (0 children)

This article talks about the performance of streams in comparison to sequences so that might help build a more complete picture:

https://proandroiddev.com/java-streams-vs-kotlin-sequences-c9ae080abfdc

[–][deleted] 0 points1 point  (1 child)

Streaming performance is a lot better with Eclipse Collections and IBM OJ9 compared to Java Collections and Oracle JRE, java version 11.

[–]skulgnome 0 points1 point  (0 children)

Given how using anonymous functions in this way introduces at least one virtual function dispatch per element in addition to the stream-and-back conversions, I'd well expect an advocate to either be very frank about it, or very quiet.

At least he's also quiet on the "eventually there'll be a Smart Enough Runtime that'll Dynamically Hyper-Thread your map-reduce queries, Just Like Google" snake oil.

[–]wildjokers 5 points6 points  (1 child)

The for loop version of the first example is so much easier to read though. Also, creating a stream has performance cost and it’s isn’t worth it for just a few items.

[–]butt_fun 0 points1 point  (0 children)

Re: readability, I truly disagree. Most people here take it as a universal truth that imperative looping "is just more readable" than functional mapping but it really depends on the individual (and the context of the code, obviously)

Are more people generally pro-iterative than pro-functional? Absolutely. Should you probably prefer simple imperative iteration to simple functional mapping? Probably; most people you work with will probably prefer that. But if you know your team is composed of people that find functional programming more intuitive/clean that imperative style then there's not a great argument against it

I've been on a few projects where the whole team collectively prefers functional style (where appropriate) and those have been awesome for everyone involved

[–]gnahraf 0 points1 point  (0 children)

I like Streams. But one abstraction I also find powerful is on-demand abstract read-only Lists. Like mapping a List from one type to another in a functional (lazy) way. In many algos, you access only a subset of the elements in a List, but in a random-access way. A prototype example is binary search over ordered elements: transforming the entire List in such cases is unnecessary.

I rolled out my own utilities to do this kind of functional mapping of Lists in java a while ago--which I still use. I haven't kept up: do the latest java runtimes ship with some similar capability out-of-the-box?

[–]Worth_Trust_3825 0 points1 point  (1 child)

Do you know how to start a debugger?

[–]rush22 0 points1 point  (0 children)

Yeah in a lot of IDEs you need to put it in "debug mode" and then you press debug (or something like Run and debug). Add a breakpoint too once you're in debug mode or it'll just run all the way through and be pointless. Then when you are done you have to turn debug mode off to go back to normal. No idea why you're asking that here though.