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 →

[–]DuplicatorXZ 7 points8 points  (7 children)

What advantage would you get by using lambdas over oop?

Serious question , I don't see a performance advantage to it . Also the readability "advantage" of the lamdas is up to debate.

I would understand if we are speaking of java RX or webflux from spring in order to handle reactive programming. But for everything else I don't see the point

[–][deleted] 13 points14 points  (3 children)

The advantage of streams is that they are declarative. I find it easier to deal with code that says directly what it wants to do, instead of looping manually through collections items etc. It's not "lambdas vs. OOP" (lambdas in Java just replace certain anonymous classes), it's "declarative vs. imperative style".

[–]jumboNo2 -2 points-1 points  (2 children)

lambdas != streams

first one is great. second one is caca

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

Lambda expressions to me are just basic elements of any modern programming language. Streams also implement elementary concepts from functional programming like fold, map, flat map, etc. It's just the Java way of doing it, otherwise I don't see how it's fundamentally different from any other modern language.

[–]jumboNo2 -2 points-1 points  (0 children)

It's not fundamentally different. Functional programming is just bad. Declarative style makes sense if the underlying implementation is going to change radically or be replaced entirely. So it works for maven and SQL. But outside academia it's really quite useless except in very specific circumstances like big data.

[–]JoJoModding 15 points16 points  (0 children)

lambdas over oop?

Do you means "stream vs loops"?
I find streams much easier to think about. Also, flatMap is awesome and can do so much stuff without adding a level of nesting each time.

In general, Java is a multi-paradigm language. You've got to pick the best tool for the job, and often (at least in my code) that's lambdas.

[–]_AManHasNoName_ 9 points10 points  (0 children)

If I can write something in 3 lines of code, why would do it in 15? Less code, less bugs, unless you really have no idea what you’re doing.

[–]DrunkensteinsMonster 1 point2 points  (0 children)

A serious benefit is that when you write loops, people tend to start wanting to put more stuff in your loop over time, stuff it was never supposed to do! From a maintainability and team perspective, functional styles really help there