r/functionalprogramming • • 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

22 comments sorted by

View all comments

Show parent comment

3

u/wojm Mar 02 '24

Logging is the exception that defines the rule. In virtually all programs it is inconsequential to log something many times vs once. This is because logging is usually only used by users and never input to another program.

The second you start relying your logs as input for another system, the side effects can have consequences.

For this reason, I don't think logging violates purity when your logging system is purely orthogonal to your application. This principle could be applied elsewhere but it's never as easy as with logging

3

u/PointOneXDeveloper Mar 02 '24

I mostly agree, the exception being experiment exposure logging, where an unexpected log due to incorrect usage of some code can mess up experiment data.

We actually solve this by having an entirely different system for experiment logging.

But to your point, the effect still lives outside anything that the code has access to. It can’t cause bugs in the program.

3

u/wojm Mar 02 '24

I think that is the right boundary. Logging has no side effects within your program but has side effects within all your systems.

This is the point where you can't think about logging as not having side effects and if you want your systems to remain pure, you can't ignore logging