Bill realizes a usecase for a new app and spends 3 days creating his first release. After hundreds of happy users, the codebase matures and becomes something somewhat stable.

But as time goes on, Bill slowly forgets the parts of his codebase. Maybe he was more junior before, maybe he was simply in a rush - but in any case, adding new functionality is difficult, and things keep breaking.

Bill wants to add tests, but every time he looks into it he realizes the tests don’t quite fit his codebase. He could mock giant objects and configure a huge state, but his tests wouldn’t cover much and each new feature would require rewriting the tests.


We’ve all been in places like Bill. Especially those of us who always chased building new apps and getting people excited. People claim testing is good, but you can’t see it. If that’s you, let me introduce you to something new: Function purity.

Function purity isn’t anything special - a function is Pure if:

  • The same input always returns the same output
  • The function does not alter any external state

C programmers begin wondering what is impure in the distance…

Pure functions are a slightly different way to approach the code - Each function does one very specific thing and takes in a handful of parameters. But one thing that’s special about pure functions is how easy they are to test.

They’re also fantastic at avoiding the slow growth of code complexity, since what you can add to the function is limited when you’re keeping its purity.

Some languages have adopted the [Pure] tag for methods as well, leaving other developers a strong hint on what the function can do. It’s always reliable, and it does exactly what you want.

Pure functions don’t make your codebase 100% testable. But they get you most of the way there - with very little effort! Despite the controversy around it, I like to pair my Pure functions with Github Copilot, since copilot can very easily generate a test class for each pure function (since pure functions are naturally so easy to test).

If you’re ever felt like testing might help, but it doesn’t in practice - Try this one out. Here’s a wiki link to get you started: https://en.wikipedia.org/wiki/Pure_function