Hacker News new | ask | show | jobs
by bontaq 1806 days ago
We've come around to something like the "imperative shell, functional core" pattern. All the business logic is purely functional (so no database calls or side effects), and any data needs are done as close to the edge of the system as possible.

You can do it in any language, FP languages can help enforce the distinction. For going even more functional, in FP languages that support it, free monads and effect systems allow you to define interpreters for effects and you can write code more or less like you would non-functionally, but the interpretation can be pure (say hardcoded results for a query) for tests, and impure for actually running. Basically fancy dependency injection, but for everything.

1 comments

agreed on IS/FC. and though I've not yet had the opportunity to use "proper" effects, I've ended up writing some micro effect systems that apply to specific systems we interact with a lot. it makes testing and reasoning about the system so much saner.