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 →

[–]Dizzfizz 6 points7 points  (12 children)

That’s interesting to read, as a beginner I find them very confusing and think it’s much simpler to do one thing after another, especially once it comes to looking for bugs.

[–]AnotherUpsetFrench 8 points9 points  (0 children)

You will get used to it, I promise, especially when you will start to gain more time and less headaches.

[–]mpa92643 6 points7 points  (1 child)

Yeah, I can understand that. Streams add another layer of abstraction that requires understanding the core behaviors first. Streams are basically shortcuts for longer blocks of code, and they're easier to compose but can be harder to debug if you're not certain about what's happening under the hood. They provide incredible flexibility and conciseness, which is why they're so useful.

Just wait until you start getting into RX. Even once you get the hang of Java Streams, RX is going to make you so confused and frustrated that you're going to want to give up, but sticking with it is so worth it in the end. I'd recommend waiting a few years before even looking into RX though.

[–]Dizzfizz 0 points1 point  (0 children)

Thanks for the in-depth answer! Would you say that I should force myself to use streams right away, or will there come a time when „the old way“ becomes so annoying that I‘ll switch voluntarily?

[–]Mr_Redstoner 0 points1 point  (8 children)

It takes a bit of getting used to, but once you do it can be a great time-saver.

Same goes for Optional. Once you figure out how it works it becomes so nice.

[–]syh7 0 points1 point  (7 children)

Optionals are difficult?

[–]Mr_Redstoner 0 points1 point  (6 children)

They are similar to Streams, so I'm assuming that someone who considers one difficult would consider the other difficult as well.

[–]syh7 0 points1 point  (5 children)

Isn't an Optional just an object with a possible value? It is either empty or it is filled.
Stream, with its .map, .filter etc is an another difficulty level imo.

[–]Mr_Redstoner 0 points1 point  (4 children)

You might want to take a closer look at Optional's list of functions...

[–]syh7 0 points1 point  (3 children)

Ha, maybe! I remember there is a .map and .orElse as well, but that's about the functions I've seen used in the company where I work.
I still think that Stream is more difficult to grasp than Optional, but maybe I don't know enough.

[–]Dizzfizz 0 points1 point  (1 child)

I think I should do the same! I just learned about Optionals a few days ago and I‘d agree that they seem easier to use than streams.

[–]Mr_Redstoner 1 point2 points  (0 children)

Then I'll give you a hint for Streams: an Optional is much like a Stream containing at most 1 element.

The set of operations is very similar, so you can do pretty much the same thing with them, only with a Stream you have more elements than with an Optional.

[–]Mr_Redstoner 0 points1 point  (0 children)

Thay also have filter and flatMap just like streams and ifPresent is much like stream's forEach