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
3
u/PointOneXDeveloper Mar 01 '24
I’m just speaking from experience that it ends up kinda sucking. I’m all for error as value, but when the language lacks the tools to handle the chaining it is pretty gross and you will get push back.
Haskell has do notation and HKTs to make clean utilities.
Rust has ? syntax and traits
Go has… erm well…
Even without the niceties at least you can’t be surprised in Go. Result/option types won’t save you when code you don’t own can still throw and you didn’t know about it. So even Go has that going for it.
Again, if you can add anything, it’s probably an Option or Result class with minimal utilities and the option to force an error for cases that the caller deems to be undefined/impossible. You’ll need team buy in though, and you’ll fight a constant uphill battle against new people joining the team and trying to use more typical idioms for the language.