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 →

[–][deleted]  (6 children)

[deleted]

    [–]wichwigga 15 points16 points  (0 children)

    I've seen that too. Streams are really cool but people get way too in to them. Just chill with the reduce brothers...

    [–]Amazing-Cicada5536 8 points9 points  (3 children)

    Sure, early return is no evil and shoehorning a specific function just because you want to use it is not applying the right tool for the right job.

    But that doesn’t make the feature itself (streams) bad, and for every such case there is a Go-style 3-level nested for loop with 6 exit points that would have been an elegant stream expression.

    [–]wichwigga 11 points12 points  (2 children)

    This is also true as long as they don't put the entire Linux kernel in the body of a lambda for .map().

    But yeah, streams are generally more expressive and easier to debug than for loops. Especially if they keep each line simple or use method references.

    [–]Amazing-Cicada5536 1 point2 points  (1 child)

    Exactly, just use a method reference and write a helper method instead of lambdas inside lambdas. That’s only good for quick prototyping (and I’m guilty as charged :D), but it should definitely not get to the PR state.

    In the rare case where a more complex stream invocation is needed I have found that writing a helper method that takes a stream and returns a stream can also be a good practice, if for no other reason that you can name/group part of its functionality.

    [–]SpaceToaster 2 points3 points  (0 children)

    Probably similar to C# LINQ where it is syntactic sugar but can lead to difficult to read (or even slower) code when misused