3 ms·
How does Scientist work with code that produces side effects? In the example, presumably both the new and old each create a merge commit. Maybe these two merge
by rcthompson 11y ago
How does Scientist work with code that produces side effects? In the example, presumably both the new and old each create a merge commit. Maybe these two merge commits are done in in-memory copies of the repo so that the test result can just be discarded, but what about in the general case where a function produces an output file or some other external effect?
- jdmichal 11y agoI would think that the operation would either (a) have to be pure or (b) be executed in two different environments. I think going for (a) is the easier approach. If you produce an output file, make a pure operation that generates the contents, then write it as a subsequent operation. Now you can test the contents against each other, but only actually write one of them. Basically, create an intermediary object that represents your state change and test those. Then "commit" the change from control and discard the one from the experiment.
- jsprogrammer 11y agoYou'd only want to use pure functions in this manner. If external state is being modified, you can use a monad, or similar, to contain it.