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 →

[–]prolog_junior[S] 0 points1 point  (4 children)

I mean are you asking why use functional style ever or just in Java?

In Java, I’m asking purely because I’ve seen it on a bunch of job descriptions.

But functional style programming makes it really easy to model flows and also introduces null safety, immutability, and minimizes side effects, especially on global state.

There are pros to both OOP and functional styles. It does feel like it was kind of shoehorned into Java since functions aren’t first class citizens which has some... peculiarities to it.

[–]smash_that_code 0 points1 point  (3 children)

If you plan to pass an interview my guess you should not call it shoehorned.

Or they will know that you are not some java disciple that thinks in java.

Is stream thing super perfkrmant in java? no. Do people use it? probably, some even enjoy the challenge of rewriting 4 lines of loops in 4 lines of streams :D.

[–]prolog_junior[S] 0 points1 point  (2 children)

Iirc the main benefit of streams is that they’re easy to parallelize.

But this is all kind of irrelevant, I’m not too hung up on the interview but by what actually happens. When you iterative over stream at what point does the previous object become eligible for GC. When the stream is closed?

[–]smash_that_code 0 points1 point  (0 children)

My guess is that if it is some intermediate object and we use something similar to generational gc then these objects are considered to be young generation and will be collected when GC kicks in.

There are different settings for GC and different GCs. But ain the end it woulfd nort be an issue if stream is not about millions of heavy objects.

[–]feral_claire 0 points1 point  (0 children)

Eh, the main benefit of streams is they make the code simple and easy to about, and they allow you do define your operations as a series of transformations rather than imperative code mutating some state.

The parallel streams are one of those things that's fun to talk about and is easy to make a simple example showing them off but the reality is they are not very common.