Codementor Events

Things to note while writing functional programming

Published Sep 13, 2017

Avoiding mutable state Functional programming will help you avoid most of the errors caused by having an unmanageable amount of mutable state in your code.

In general, it's useful to carefully consider where in your program you definitely need state and where it can just be avoided altogether using a more functional approach.

Having working code in production that is less prone to bugs is usually of greater importance.

Imperative languages often offer standard libraries to try to help reduce the complexities of having to handle concurrency in your code.

Functional programmers argue that state changes over an immutable state are easier to reason about, and that's probably true for most people.

Purity can backfire Another common strength of functional programming is the ability to abstract over side-effects and build a pure set of computations that can be composed into a program that is mostly free of side-effects.

If you are building a compiler or a mathematical model a functional language can be a great fit.

Some developers take purity a little too far by trying to shoehorn every solution into a pure computational model resulting in very convoluted code.

Ten levels of monad transformers or using the shiny new extensible effects won't look that much of an improvement compared to some boring code that deals with your database, your HTTP calls, or the email client you are using, when that's all it's doing.

Think about the solution Code that is 100% pure, immutable, parallelisable and free of side-effects doesn't guarantee a working production system.

I've seen incredibly beautiful functional code doing the wrong thing, creating too much coupling between components of the application, or not handling failures at all.

Discover and read more posts from Etanuwoma Jude
get started
post commentsBe the first to share your opinion
Show more replies