Deterministic Core, Non-Deterministic Shell
4 hours ago
- Functional Core, Imperative Shell separates pure business logic (Core) from IO and side effects (Shell), improving testability.
- The Core is deterministic: same inputs always yield same outputs, making it easy to test without mocks.
- Deterministic Core, Non-Deterministic Shell broadens the principle by focusing on determinism, not just purity, allowing imperative code if it's deterministic.
- Non-deterministic behaviors (e.g., RNGs, async, network, DB, date) should be isolated in the Shell, not the Core.
- Existing codebases can be improved by 'defragmenting determinism': finding and grouping deterministic parts, even if not fully refactoring.
- Every messy codebase likely contains hidden deterministic state machines, which can be extracted for easier testing and modification.
- Use practical strategies: split functions, lift non-determinism, and inject results as parameters.