Rescuing Legacy Code by Extracting Pure Functions

I ran into a similar issue recently. I have a legacy code base, and I want to extract pure functions from the code. The problem I was running into was that not all of the state could be extracted into either input parameters or output return values. For example, let's say you have a logger which runs in the middle of your "pure" function. Usually it isn't a big deal to leave a logger in your code, but sometimes you want to invoke your pure function without logging. I posed the question on StackOverflow, looking for answers. http://stackoverflow.com/qu...
I came up with a way to do this: add callback functions as parameters to your pure function. Any time you want to change state, instead, call a callback function to do so. In your production code, the callback would alter the state. If you're testing the code, the callback is NULL, and never called. I made a GitHub repo and made some examples in different code. https://github.com/daverobe...