Pure functions

Pure functions are an effin REVELATION!

After learning about pure functions you’ll never want to write functions in any other way.

The whole thing is pretty simple and straightforward.

When you write functions you pass to them everything they need from the outside scope then the function does what you need it to do and finally you return a result but there’s a big twist here, the function can’t affect anything outside it’s scope so the only way for a function to ‘communicate’ with the outside world (actually do anything and be useful) is with the return

This doesn’t seem like much but this rule forces you to write lean specialized functions that don’t do a lot of things but the things they do, they do well.

This makes pure functions predictable since if you pass to it the same input no matter how many times you will always get the same output. Nice.

Another positive side effect of pure functions is that by their very nature they’re simple, which means they’re easy to reason with, which means developers don’t need to invest too much brain power into thinking what exactly your code does and on top of that they’re easy to test.