Pure functions are often hyped up in the JavaScript world, probably because of the abundance of stateful front end applications. While pure functions have their downsides (i.e. inconvenience, potentially large argument lists), they should be used as much as reasonably possible.

We’ve made a lot of changes in the Qvault app codebase recently to use more pure functions, and it has helped make the code easier to understand and write tests for.

What is a Pure Function?

According to Wikipedia, a Pure function has the following properties:

  1. Its return value is the always same for the same arguments
  2. Its evaluation has no side effects (no mutation of data outside the function)

Which means that as a developer I know two important things:

  1. When I call a pure function I will get the same result every time
  2. After calling a pure function the rest of my program will be in the same state it was before calling it

#golang #clean code #engineering practices #languages #go #golang #programming #pure functions #testing

How to Make Pure Functions (Go)
1.10 GEEK