Introduction

In this article, I am going to explain the fundamental concepts behind functional programming and advantages of these languages over procedural programming.

What is Procedural Programming?

Generally, we call procedural programming as "imperative" meaning specifying the steps the program should take to achieve the result. Mathematically, modifying the values of variables by statements and expressions like:

Variables and their values make procedural programming as "state" based means changing from input state to output state. Here, the output is deterministic as

where, f is a function.

Simply we can say, procedural programming contains the following type of statements:

Sequential

Conditional

Repeated

What is Functional Programming?

In this section, let us first understand where functional programming differs from procedural programming.

Variables are Values

There is no state mechanism in functional programming that is variables are to be considered as values.

Sequence is Meaningless

In functional programming, sequential statements are meaningless meaning that there are no repetitive statements. Instead, it provides a mechanism called recursive meaning a function calls itself. For example, let us write a program to calculate the sum of the given range in both procedural and functional programming.

In the above functional program, you can see the power of recursive approach and variables are treated as values. The recursive as shown in the above program is possible in modern procedural languages including C++, C# and Java. However, I'll show the real benefit of this in functional programming in later sections.

Functions are Values

Functions can be treated like values so you can pass these as argument, return as function values and calculate it with others (this one is shown in Code 3).

Immutable Data Structure

We know that immutable means state of an object cannot be modifiable after creating it. In .NET, string is one of the good examples for this. Immutability makes programs much simpler since there is no need to perform copying and comparing. However, immutable to all objects does not make sense in the real world programming. This would affect system performance. In pure functional perspective, objects are immutable. Let us find how the functional programming implementation handles this in a later section.

Let us consider an immutable collection, every time you add an item into this, as per theory, a new object will be created. So, to add four integers into an immutable collection MyList:

Code 5 shows that the XPowerN is curried in functions Square and Cube.

End Note

In this section, we have seen what is functional programming and how it differs from procedural programming. In the next part, I'll explain the origin of functional programming lambda calculus and advantages of functional programming.

No, I think not. While the contents of cells in a spread sheet can be declared as depending on other cells and updated seemingly automatically, the cell values are mutable and spreadsheets differ between functions and values, to name a few things that differs.

I would disagree with TobiasP and say that you are completely right: creating a spread sheet is essentially the same as creating a small program in a functional language. You only define immutable values and functions in a sheet: extremely functional-like. Compared to other languages, it is just missing a concept of "interface" for the "class" and "function", but you could partially fake that by defining input and output of your "function" (Spreadsheet) as named ranges. Though it would be quite a hack...

But all the same - I think the principle is the same.

In fact I was thinking once of creating a tool that would read Excel sheets and make F# code out of it. But then gave it up - I have real work to do.