Woodstock Blog

a tech blog for general algorithmic interview questions

[Design] Functional Programming

Overview

A functional language allows you to write a mathematical function, i.e. a function that takes n arguments and returns a value. If the program is executed, this function is evaluated.

A purely functional program always yields the same value for an input, and the order of evaluation is not well-defined; which means that uncertain values like user input or random values are hard to model in purely functional languages.

One Sentence

Functional programming is like describing your problem to a mathematician. Imperative programming is like giving instructions to an idiot.

Pros and Cons

Functional Programming allows coding with fewer potentials for bugs because each component is completely isolated. Also, using recursion and first-class functions allows for simple proofs of correctness which typically mirror the structure of the code.

Functional programming languages are typically less efficient in their use of CPU and memory than imperative languages such as C and Pascal.