3 ms·
>The best approach is separating the calling of the external dependency (getting the time) to it's own function That is the FP maximalist approach and many of
by munksbeer 3y ago
>The best approach is separating the calling of the external dependency (getting the time) to it's own function
That is the FP maximalist approach and many of us reject it.
So no, it is not the best approach.
We use a time provider interface and mock it, and have zero problems with this approach.
- marcosdumay 3y agoThe FP maximalist is writing your code in a monad that implements a timer. It looks quite similar to the OOP maximalist people are pushing here.
- hnfong 3y agoSo, "yes, we're writing the same thing, but because monads I'm still pure and you're not"?
- marcosdumay 3y agoKinda yes. And technically, it's still pure. It does fit well a small set of problems and break in surreal nightmarish ways for everything else; just like the OOP's maximalist DI. It is worse in that you are injecting an entire interpreter instead of just a few functions, but this doesn't create as many problems on practice as it looks like it should. And it's better because idiomatically the injection tends to be explicit and well defined; and if your DI doesn't have at least one of those, it will again break in surreal nightmarish ways. (And here I have to point out that in OOP-land, web frameworks are allergic to well defined interfaces - what means that you can create one, but if you insist the framework tends to choke and die. So, if you are writing for the web in OOP, there's actually only one option.) But well, it's not surprising that the maximalist options all break in similar ways.