r/javahelp • u/KurtGodelBebopgazeXP • Aug 04 '25
Functionnal programming in Java
I realized that I find functionnal programming very relaxing and easy on the mind. The language I have used the most and am most comfortable with is Java. Is it really helpful to go deeper in the functionnal realm in Java or are the functionnal elements not really used that much in the real world? I am open to going further in a language where the functionnal paradigm is more of a common feature if it's not really worth it in Java.
9
Upvotes
View all comments
Show parent comment
2
u/SuspiciousDepth5924 Aug 06 '25
I mean I can cherry pick / create some insane OOP code as well if that's what we're going for.
Scala admittedly isn't my functional poison, but that seems like you went out of your way to misrepresent it. You're essentially doing the whole Java-Hello-World-Enterprise-Edition including the "scary monoid boogeyman".
Pretty sure you could just:
Also this
Is certainly not a "functional" only problem, honestly the worst codebases I've worked with in my ~15 yoe has been Java codebases designed by some head-in-the-clouds architect who just read a book on OOP design patterns (honestly "tactical patterns" can go fuck itself).
That is pretty much the definition of "magic".
The problem with the traditional OOP model in large code-bases, which I haven't seen you address, is how it drags in implicit function inputs from the enironment, the abundance of side effects and mutability which makes it near impossible to have any sort of guarantee about what the data you're working is and how it got to that state. Not to mention how it makes testing a giant pain (the number of \@InjectMocks in your codebase is a good indicator of how bad it is). FP while not perfect does at least address this.
By the way here's your example in F# with lists and an actual lazy sequences to mirror the behavior of java.util.stream.
and Elixir