DEV Community

Discussion on: Practical Functional Programming in JavaScript - Side Effects and Purity

mikearnaldi profile image
Michael Arnaldi • Edited on

"Functional Programming" as in Programming with Functions can only be pure because a non-pure function is simply NOT a function (it is a procedure). It might be argued that the lazyness is optional, and in fact it is but as soon as you write a side effect inside one of your "functions" and that gets executed you will transform by definition your program to be procedural given the composition of a function with a procedure is a procedure.

Thread Thread
richytong profile image
Richard Tong Author

I would just like to point out this interesting take from the MDN web docs on functions. (link)

A function is a JavaScript procedure—a set of statements that performs a task or calculates a value.

It sounds like they're saying a function and a procedure are the same. Is there a misunderstanding here?

Thread Thread
mikearnaldi profile image
Michael Arnaldi

There is a misunderstanding, the definition of function is a binary mapping between sets. The interpretation from MDN is strictly related to the world of programming languages where the term function is improperly used to represent any procedure. It is not the meaning used in "functional programming" where functional refers to a classic function. Sometimes in programming we like to add the term "pure" to denote when a function (from the language perspective) is actually a function.

One thing to note is that all of the nice properties of "pure" functions that are leveraged in FP are almost never respected when functions are not "pure" (or better, not functions)