3 ms·
In the testing example, I honestly don't see the value of the suggested approach over passing in two continuations. In production, the actual I/O methods can be
by kqr 7y ago
In the testing example, I honestly don't see the value of the suggested approach over passing in two continuations. In production, the actual I/O methods can be passed in, and in testing we can pass in functions that validate their arguments.
This "dependency injection" type approach would be... functionalisation (?) i.e. the opposite of the suggested approach. But it also leads to greater decoupling.
I often find refactoring in the spirit of functionalisation more powerful, because then what I do becomes less about implementing a specific piece of logic, and more about creating a robust library of combinators that can be puzzled together to implement the desired business logic. In my experience, getting combinators right is easier but also more productive.
With the suggested approach, changes to the logic requires mirroring sets of changes across many locations (because of the expected protocol of discriminated cases), whereas the functionalised code requires changes only either in the continuations or in the combinator, but generally not in both.
- gridlockd 7y ago> I often find refactoring in the spirit of functionalisation more powerful, because then what I do becomes less about implementing a specific piece of logic, and more about creating a robust library of combinators that can be puzzled together to implement the desired business logic. The problem here is that your state is almost always transient and non-inspectable. Almost all the complexity in any non-trivial program is in the state, whereas the transformations are usually trivial and things like combinators don't really matter one way or another.