Simplify Your Code: Functional Core, Imperative Shell
Simplify Your Code: Functional Core, Imperative Shell
Homepage   /    other   /    Simplify Your Code: Functional Core, Imperative Shell

Simplify Your Code: Functional Core, Imperative Shell

Google 🕒︎ 2025-10-28

Copyright googleblog

Simplify Your Code: Functional Core, Imperative Shell

Is your code a tangled mess of business logic and side effects? Mixing database calls, network requests, and other external interactions directly with your core logic can lead to code that’s difficult to test, reuse, and understand. Instead, consider writing a functional core that’s called from an imperativ​​e shell. Separating your code into functional cores and imperative shells makes it more testable, maintainable, and adaptable. The core logic can be tested in isolation, and the imperati​​ve shell can be swapped out or modified as needed. Here’s some messy example code that mixes logic and side effects to send expiration notification emails to users: A functional core should contain pure, testable business logic, which is free of side effects (such as I/O or external state mutation). It operates only on the data it is given. An imperative shell is responsible for side effects, like database calls and sending emails. It uses the functions in your functional core to perform the business logic. Rewriting the above code to follow the functional core / imperative shell pattern might look like

Guess You Like

Man killed in elephant attack while collecting mushrooms
Man killed in elephant attack while collecting mushrooms
"A man on Friday lost his life...
2025-10-20