Avoid Mutable State

A necessary feature of a purely functional language is that it has no side effects; functions are supposed to return an answer based on arguments, but nothing in the system should be changed by executing a function.

This often strikes programmers new to functional programming paradigms as strange, because to them, the point of a program is to change or “mutate” some state somewhere and record it or show the new state to the user. And this hints at some of the differences in the types of problems pure functional language programmers want to solve compared to “the rest of us.” But there are benefits to avoiding mutable state in any system.

One of the most relevant benefits of having no mutable state in a function is that ...

Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.