Functional Programming

1/4/2016

What exactly is functional programming? Functional programming is basically programming built around functions. Now if you know ruby or javascript you have an idea of what a function is already. It is a bit of code that performs a task and returns a value. Functional programming is a type of programming where you use functions to accomplish tasks.

As opposed the most popular type of programming, imperative programming, functional programming is based off lambda calculus. There are a couple of basic concepts to understand when practicing functional programming. First, are Higher Order and first class functions. Higher Order functions return other functions as their return value, and first class functions can be used anywhere in a program. These are useful when passing information between functions and when implementing recursive functions. Second, functions in functional programming should be immutable this simply means they cannot be changed, so instead of altering an array you create an whole new one. Third, functions in functional programming should be stateless, meaning they always operate as if it is their first time operating, they don't rely on data that is not passed to the function. Lastly, you need to understand recursion, which is many things but one of which is a handy method to avoid looping. Recursion is basically calling the function itself inside the function. You would do this as an alternative to looping. It also makes programs more efficient.

There are several functional programing languages like Haskell, Erlang, and Scala. These and many other functional programming languages were originally designed for academic use, except Scala. Functional programming is less memory efficient than imperative programming, so therefore less popular. There are companies that use functional programming for more math related operations in engineering and data science. One of these is twitter which designed the functional programming language scala to help with its data analysis.

All in all it is important to understand the concepts behind functional programming because they make us better programmers even if we only use imperative languages.