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
0
u/[deleted] Mar 05 '24 edited Mar 05 '24
FP is not so much about designing, but rather about implementing programs.
FP does not mean leveraging anything, it [almost literally] means the absence of certain kinds of things, of which side-effect is the most notable [the other 2 are non-termination and non-determinicity].
It is a requirement and it does not make the programs useless.
They do. Pure means that their semantics does not allow side-effects. Though in practice Haskell does give an escape-hatch ["unsafePerformIO"] from that prevention system.
I suspect that you are confusing effects and side-effects. Programs need effects. But effects do not need to be expressed 'to-the-side'. Haskell and friends make us able to express effects ["Haskell is the best imperative language"] but normally not allow side-effects.