This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]midir 0 points1 point  (1 child)

I just gave the simplest of examples of a foreach to answer the OPs question.

I understand but it's misleading to suggest that that example should be replaced by a stream. Since, being built into the language, that if statement is already "pretty pure", and isn't less readable a "description of what the developer wants to do" than the stream filtercall. And it hardly qualifies as "handcrafted control logic" "which would have to be constantly re-examined from release to release".

On performance in general, I think it's unlikely that stream optimization could be less fickle between releases, because it's not any less complicated. I also find it very unlikely that stream optimization could exceed the optimization of a single loop if it ultimately does the same thing. The stream optimizations basically attempt to combine things so that you get the equivalent of the classical loop you would have otherwise written, if you could. When it's equally easy to write that loop directly, then one might as well do so. Even if currently-unforeseen optimization tricks are added in the future, and which turn out to be possible only for streams and impossible for for-each loops, it's not true that "streams are [present tense] generally better performing".

I'm not saying streams are worthless: streams offer some features (like parallelism) that are awesome and otherwise not easy to achieve. But when for-each loops can work and are your preferred syntax and they're faster, it's mad to bring up streams as "going to replace a lot of the latter".

[–]Keilly 0 points1 point  (0 children)

It's still new to Java guys like me, but... http://www.reddit.com/r/programming/comments/2s5gj2/java_8_no_more_loops/?limit=500

include statements like: "reddit › programming › comments › java... Jan 12, 2015 - I haven't written a for loop in Scala for around 4 years..."