What is Functional Programming?

Functional programming is simply writing functions that only operate on the given parameters and local variables and then return a value.

//functional programming
int add(int a, int b) { return a+b; }

//not functional programming
int a,b;
a=2;
b=3;

int add() { return a+b; }

Functional Programming is great in theory because you can test functions easily. You just call the function with values and check to see if the returned value matches the expected value.

In non-Functional Programming you may have to create some global values before you can test the function.

I’ve been running some tests in C# and am finding that it is actually faster to declare a variable locally and act on it than to use a variable defined at the class level. I’m going to keep running tests to verify these results.

Leave a comment

You must be logged in to post a comment.

ss_blog_claim=70b9168863fc97c91e6d88b40542a327 ss_blog_claim=70b9168863fc97c91e6d88b40542a327