March 30th, 2019


Functional programming is a style of writing software that stresses using pure functions, avoiding modifying global state and employs declarative statements. Declarative programming style instructs what needs to get done, instead of how. Functional programming treats computation as the evaluation of mathematical functions. This is opposed to object oriented programming, which is based on modifying global state.

Pure functions are functions that have the same output for the same input. They do not depend on and do not modify any global state. For example: calling a function with the same input twice will give the same output. Pure functions can be easily isolated, and reused. This makes testing and thinking about the code very easy, as you do not require to set up any environment and not worry about hidden edge cases. To test, you only need to pass in a value and expect to get a value returned.

When using pure functions, memoization is very easy, you only need to calculate the output for an input once and cache the result. This is easy as no global state is modified and there are no side effects of the function.

Functional programming avoids changing global state, stresses immutability and uses declarative statements.

Contact