jspωiki
Functional Programming

Overview#

Functional Programming is a programming paradigm where the there is no reliance on data outside the current function and there is no change to data that exists outside the current function.

This is Functional Programming:

def increment(a):
    return a + 1

This is NOT Functional Programming:

a = 0
def increment():
    global a
    a += 1

Functional Programming has its origins in lambda calculus, a formal system developed in the 1930s to investigate computability, the Entscheidungsproblem, function definition, function application, and recursion. Many functional programming languages can be viewed as elaborations on the lambda calculus.[2]

idempotent (ie Immutable)#

Functional Programming operations (or service call) should be idempotent, implying that clients can make that same call repeatedly while producing the same result. In other words, making multiple identical requests has the same effect as making a single request. Note that while idempotent operations produce the same result on the server (no side effects), the response itself may not be the same (e.g. a resource's state may change between requests).

There are also some caveats to remember. (Although we show HTTP Request, this is applicable to many other Protocols)

The HTTP PUT and HTTP DELETE methods are defined to be idempotent. However, there is a caveat on HTTP DELETE which if successful would normally return a HTTP 200 (OK) or HTTP 204 (No Content), will often return a HTTP 404 (Not Found) on subsequent calls, unless the service is configured to "mark" resources for deletion without actually deleting them. However, when the service actually deletes the resource, the next HTTP DELETE will not find the resource to delete it and return a 404. However, the state on the server is the same after each HTTP DELETE call, but the response is different.

HTTP GET, HTTP HEAD, HTTP OPTIONS and HTTP TRACE methods are only intended for retrieving data which makes them idempotent as well since multiple, identical requests will behave the same. (Again assuming the state of the resource is the same)

More Information#

There might be more information for this subject on one of the following: