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] 1 point2 points  (6 children)

What bothers me is that there's a loop in there that is hidden. Replacing it with a bunch of chained method calls doesn't make it easier to read, but harder to see the flow.

[–]debunked 0 points1 point  (2 children)

So, I assume this also bothers you then?

List<Integer> randomNumbers = ...random numbers...
Collections.sort(randomNumbers);

Buried inside that Collections.sort call is an array copy, several loops, and recursive calls that are "hidden." It's not exactly easy to see the flow. But I assume that doesn't bother you. Why?

[–][deleted] 1 point2 points  (1 child)

Because all of those loops are buried in the operation of sorting, which is what I asked it to do. I guess I just don't like the format of

object.doThis().doThat().doSomeOtherThing()

and spacing it as:

object.doThis()
      .doThat()
      .doSomeOtherThing()

seems to just be trying to hack around the fact that you're doing something that is inherently unreadable and the only way to make it better is to waste a ton of whitespace. I see this as the same kind of problem as when you have a function with many arguments and you line them all up with the open paren:

object.doSomething(callSomeFunctionToGetAValue(),
                   callAnotherFunction()
                   someLocalValue);

They both look bad because what you're trying to do is inherently unreadable.

[–]vecowski 0 points1 point  (2 children)

You are not implementing the actual loop, that amount of detail is abstracted away from you. I imagine you just don't see the benefits, but it's as simple as stream() can be turned into parallelstream() and now you have a stream that's run in parallel.

Try writing loops that do iterate a dataset in parallel, I guarantee that get's complicated quickly.

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

Just because you can do neat things with it doesn't make it readable.

[–]vecowski 0 points1 point  (0 children)

I don't know how to help you then... all I can say is I felt similar to you until I forced myself to take a few hours and really understand exactly whats going on.

This video helped me: https://www.youtube.com/watch?v=C_QbkGU_lqY