Pragmatic Functional Programming

There are two approaches to functional programming:

  1. Use abstruse concepts ad ridiculum, or
  2. Implement logic in pure functions.

The difference is a matter of experience. The inexperienced imagine that exotic complexity will serve them. The experienced know that familiar simplicity will serve everyone.

The second approach immediately leads to immutable data. It will also lead to more advanced functional concepts, as needed. That is the critical difference. If you jump straight into advanced concepts, you fill your head with solutions looking for problems. That is a recipe for garbage.

If you begin with pure functions, you can greatly improve even your object-oriented, production code. Classes will simply:

  1. Initialise state,
  2. Create the next state by composing pure functions, and
  3. Decide whether to accept the new state.

Then side effects can trigger in response to state changes. The effectful code is vastly simplified, since most logic is handled elsewhere.

The result is that most of your code is pure functions. Therefore, most of your code is testable, composable, runnable in parallel and more. This is a smart way to code that you can apply almost anywhere. You can view it as merely separating the concerns of logic, state and IO—no complexity required.