r/functionalprogramming • u/Jiruze • Mar 01 '24
Question Functional in OOP code base
Is it practical to write functional code inside a highly OOP code base?
I'm tired of searching through every instance of a state variable to analyse the impact. OOP often hides the data flow behind procedures, which took me some additional time to understand a piece of code. I wonder if I could at least try to change how it written so it easier to understand and debug?
11
Upvotes
View all comments
Show parent comment
5
u/[deleted] Mar 01 '24
Haskell would be much more ergonomic with that, true, but even in bad languages [Java, C#, ...] a Result type is better than exceptions. I state this based on my intuition and practical experience in programming Haskellishly in C# for a few years. One can propagate that Result type higher much more easily than an average coder would think at first. One just needs some helper functions, like
Unfortunatly one needs to write asymptotically more such swap functions than in Haskell, because of the lack of higher kinded types, but it is doable.
The rest of your comment is exceptionally well said in my opinion.