A functional programming language is one that does things by evaluating functions. Many functional programming language only allow for pure functions which have no side effects.
Functional languages are generally considered more rigorous and mathematically correct. Purely functional programming is often considered difficult due to the restrictions placed on state manipulation.
One benefit of purely functional programming languages is their application to parallel computing. Since there are no side effects, tasks can be automatically distributed over multiple processing units without concern.
A pure function is one that takes input, and produces output without relying on any other state except for the input. This means that we can make an important assumption about a pure function: given the same input, it will always produce the same output. We cannot make this guarantee about impure functions!
# -*- mode: python; -*- def pure (x): return x*x # External State y = 10 def impure (x): global y y = y + x return y*x
In this example, every time we call pure(5) we will get the same result (25). However, every time we call impure(5) we will get a different result.
Haskell is an example of a pure functional language. Ruby is an example of an imperative language with impure functional features.