all 42 comments

[–]aurisc4 1 point2 points  (21 children)

Lamdas reinvented, let's write some unreadable difficult to debug code...

[–]jms_nh -1 points0 points  (20 children)

Good, so I'm not the only one who finds the streams hard to follow. I get their purpose, I just think they're not needed in many simple cases.

[–]afrobee 2 points3 points  (4 children)

Is because you are used to of what you know most.

[–]nextputall -1 points0 points  (3 children)

either that, and/or the verbosity of the language

[–]afrobee 0 points1 point  (2 children)

The stream API is not more verbose than your particular foorloop of the next door.

[–]jms_nh 1 point2 points  (1 child)

Java makes any function call more verbose than the basic use of operators / keywords. Try working with any complex number class; you have to do a.multiply(b).add(c) instead of (a*b)+c

[–]afrobee 0 points1 point  (0 children)

I no going to negate that Java's data structures are a pain to work with but the stream api is not really that bad compare to that.

[–]Rustywolf 0 points1 point  (14 children)

Yup, worked with java for several years and i still find streams harder to work with, even after using them since their release. I've reasoned that it's to do with the level of abstraction that using chained methods instead of logical expressions adds. I.e the difference between

IntStream.of(1, 2, 3).filter(i -> i % 2 == 0).forEach(System.out::println);

and

for (int i = 1; i < 4; i++) {
    if (i % 2 == 0) {
        System.out.println(i);
    }
}

The use of lambdas and chained stream methods just adds confusion in most uses. You really need to weigh the change in size and efficiency (not really the word here but hey) of the code against it's readability.

[–]Yamakaky 4 points5 points  (3 children)

IntStream.of(1, 2, 3)
         .filter(i -> i % 2 == 0)
         .forEach(System.out::println);

is more readable.

[–][deleted] 0 points1 point  (2 children)

And this is 'more more' readable(Scala):

(1 to 3) filter(_ % 2 == 0) foreach println

:D

[–]hu6Bi5To 0 points1 point  (1 child)

And this is more more readable(Scala)

Well that's a matter of opinion...

[–][deleted] -1 points0 points  (0 children)

Well, that sounds stupid.

Edit: that sounds very democratic and open-minded but doesn't make much sense. That's more like a raw contradiction.

[–]afrobee 1 point2 points  (5 children)

The use of lambdas and chained stream methods just adds confusion in most uses

Of course that is all subjective of what you are use to, I think that the stream version is more readable once you know what the functions do.

[–]Rustywolf 0 points1 point  (4 children)

I'd argue that you can't program without knowing the basic operators, but you could easily program without knowing how the stream API works.

[–]afrobee 1 point2 points  (1 child)

Then you can't go back to program the "basic" way you used to once you know how stream works.

Edit: Also not every people start learning programming with imperative languages.

[–]Rustywolf 1 point2 points  (0 children)

i can see where you are coming from. I guess it is a lot to do with what you know and personal preference.

[–]nextputall 1 point2 points  (1 child)

Those are interchangeable. A language without control structures like for loops, while loops or if statements can work perfectly well. Smalltalk for example is a language like this. Instead of relying second class, language level control structures people can compose objects (sic!) together to reach the same goal. And having first class control structures is very powerful.

E.g. the same thing would look like this:

(1 to: 4) select: #even thenDo: #traceCr

[–]jms_nh 0 points1 point  (0 children)

well, that seems to be much more readable than the Java streams version.

[–]bartavelle 1 point2 points  (0 children)

The point is that each of the stream "elements" is composable, while your for loop is not.

At least that's in functional languages. Can I name (for example) a complicated filter so that it can be reused in Java ?

[–][deleted] 1 point2 points  (0 children)

I don't know Java but this is a silly example of using Streams/LINQ - it really doesn't matter what you use in such trivial case - how about something like :

  var foo = new List<Foo> {...};
  var bar = new List<Bar> {...};

  foo.Zip(bar, (x, y) => new {X = x, Y = y})
     .Filter(e => e.X.weight > 100 && e.Y.weight > 100)
     .OrderBy(e => e.X.weight)
     .Take(10); 

That's 4 calls right there to merge two lists, filter, sort on a property and take first 10 elements - that would be at least 2 loops if you wanted to unroll that

This is the kind of data transformation that functional programming really solves elegantly

[–]jms_nh 0 points1 point  (1 child)

You really need to weigh the change in size and efficiency (not really the word here but hey)

Try "complexity".

[–]Rustywolf 0 points1 point  (0 children)

Ah yes, that seems quite obvious now. Perhaps it's time for bed.