Refactoring: Replace Side Effects with Return Values
Hi Folks,
We’re diving into a large refactoring at work, and we discovered an interesting little pattern in the process. As with many developers, we are on an FP bender and are striving to make our code more functional and declarative.
We have a few third-party libraries which are imperative by nature: They only do interesting stuff via side effects. We wanted to turn those side effects into return values to make testing and logging easier.
Thus, we created a pattern we're calling Replace Side Effects with Return Values. It’s useful to keep in the tool belt for turning imperative legacy code into easily-testable functional code.
Enjoy!
Don't miss what's next. Subscribe to Kelly Sutton’s Newsletter: