Google Testing Blog: 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 imperative 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 imperative 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: // Bad: Logic and side effects are mixed function sendUserExpiryEmail(): void { for (const user of db.getUsers()) { if (user.subscriptionEndDate > Date.now()) continue; if (user.isFreeTrial) continue; email.send(user.email, "Your account has expired " + user.name + “.”); } } A functional core should contain pure, testab
Google Testing Blog: Simplify Your Code: Functional Core, Imperative Shell Testing Blog Simplify Your Code: Functional Core, Imperative Shell Monday, October 20, 2025 Google Labels: Arham Jain , TotT    Labels  TotT 113 GTAC 61 James Whittaker 42 Misko Hevery 32 Code Health 31 Anthony Vallone 27 Patrick Copeland 23 Jobs 18 Andrew Trenk 13 C++ 11 Patrik Höglund 8 JavaScript 7 Allen Hutchison 6 George Pirocanac 6 Zhanyong Wan 6 Harry Robinson 5 Java 5 Julian Harty 5 Adam Bender 4 Alberto Savoia 4 Ben Yu 4 Erik Kuefler 4 Philip Zembrod 4 Shyam Seshadri 4 Chrome 3 D
related reading
- Google Testing Blog: Code Healthtesting.googleblog.com
- Google Testing Blog: Less Is More: Principles for Simple Commentstesting.googleblog.com
- Google Testing Blog: Write Change-Resilient Code With Domain Objectstesting.googleblog.com
- Google Testing Blog: Code Health: Reduce Nesting, Reduce Complexitytesting.googleblog.com
- Google Testing Blogtesting.googleblog.com
- Cognitive load is what mattersminds.md
- How to Write Clean, Testable Codeyoutube.com
- Google Testing Blog: How Much Testing is Enough?testing.googleblog.com
- Google Testing Blog: Testing on the Toilet: Test Behaviors, Not Methodstesting.googleblog.com
- Google Testing Blog: Communicate Design Tradeoffs Visuallytesting.googleblog.com
- Write code that is easy to delete, not easy to... — programming is terribleprogrammingisterrible.com
- Software Engineering at Googleabseil.io