Functional languages put emphasis on expressions and declarations rather than execution of statements. Therefore, unlike other routines that depend on local or global state, the value output in FP depends only on the arguments passed to the function.
Features of Functional Programming
- Functional programming method focuses on results, not process.
- It emphasizes what will be calculated.
- The data do not change.
- Functional programming splits the problem into functions.
- It is built on the concept of conditional expressions and mathematical functions that use recursion to perform the calculation.
History of Functional Programming
The basis of Functional Programming is Lambda Analysis. It was developed for functional application, definition and recursion in the 1930s.
LISP was the first functional programming language. McCarthy designed it in 1960.
In the late 70's researchers at Edinburgh University took the ML (Meta Language)
In the early 80s, the Hope language adds algebraic data types for recursion and equational reasoning.
In 2004, it became prominent as Scala in functional language.
Functional Programming Languages
The purpose of any FP language is to imitate mathematical functions. However, the basic calculation process is different in functional programming.
Here are some important functional programming languages:
- F #
- ML / OCaml Lisp
Basic Functional Programming Terminology and Concepts
Literal data means you can easily create data structures instead of changing what already exists.
Functional programs should perform operations as if it were the first time. Thus, you will know what may or may not happen during the execution of the program and its side effects. It is called reference transparency in the term FP.
Modular design increases efficiency. Small modules can be encoded quickly and have a higher chance of reuse, which definitely leads to faster development of programs. Apart from that, the modules can also be tested, which helps you reduce the time spent on unit testing and debugging.
Sustainability is a simple term, meaning FP programming is easier to maintain as you don't have to worry about changing anything other than the function accidentally given.
First Class Function
'First class function' is a definition attributed to programming language entities that have no restrictions on their use. Therefore, top-notch functions can appear anywhere in the program.
Closure is an internal function that can access parent function variables even after the parent function has been executed.
High level functions
High-level functions allow partial implementations. This technique applies a function to its arguments one at a time, as each application returns a new function that accepts the next argument.
A 'pure function' is a function whose entries are declared as input and none of them should be hidden. Outputs are also reported as output.
Pure functions affect their parameters. If it doesn't return anything, it's not efficient. It also offers the same output for given parameters.
The impure function is just the opposite. It has hidden entrances or exits. Impure functions cannot be used or tested alone because they have dependencies.
Function composition combines 2 or more functions to create a new function.
What is a monad?
Monad word meaning is the smallest objects such as atom and unit. In functional programming, it is the neutralization of side-effect operations (eg null) that may cause errors by wrapping them with optional types such as Maybe.
Benefits of Functional Programming
- It ensures that you don't confuse problems and errors in the code.
- Parallel processing and concurrency
- It offers better modularity with shorter code.
- Increased developer productivity
- Supports nested functions
- Allows effective use of Lambda Mathematics
Limitations of Functional Programming
- The functional programming paradigm is not easy to understand, so it is difficult for beginners to understand.
- It is difficult to get many objects to evolve while encoding.
- Requires extensive environmental setup.
- Reuse is very complex and must be constantly reorganized.
- Objects may not represent the problem correctly.
As a result
Thanks to functional programming, we can instantly define functions as variable definitions, write small functions that will make our work easier and connect them to work with each other. If you have questions and comments about functional programming, you can write to us in contact.