Introduction to Functional Programming
Jerónimo Calvo Sánchez
Software Engineer | Team Lead | Scrum Master | Project Manager
What is Functional Programming
In Computer Science, Functional Programming is a programming paradigm that decomposes a problem into a set of Functions. A Function (also known as procedure, method or routine) is a unit of software logic that has a well-defined interface and behaviour and can be invoked multiple times.
This paradigm is in contrast with imperative programming, where a sequence of imperative statements update the running state of the program.
Purely Functional Programming
A subset of Functional Programming is Purely Functional Programming, where pure functions are used, and therefore it is needed to avoid mutable states and minimize side effects
Pure Functions
A pure function is one that
Data is Immutable
In order to enforce functions deterministic behaviour, data is treated as immutable: once data is created, it should not be modified. Instead, new data structures are created rather than altering the original.
领英推荐
Minimize Side Effects
A Side Effect is any observable effect other than the primary effect of reading the value of its arguments and returning a value to the invoker of the operation: this occurs when a function modifies anything outside its scope or interacts with the outside world (e.g., writing to a file, changing a global variable, or printing to the console).
In Purely Functional Programming, side effects are minimized or isolated.
Main Benefits
Main Challenges
Most of real world application will require to be aware on external factors that will make functions return different outputs for the same inputs. An example can be when my functions depends on an external web service
Some History
In recent years, functional programming concepts have been incorporated into multi-paradigm languages such as Java, Python, and JavaScript, making them more accessible to mainstream developers But Functional Programming origins lie in academia, dating back in 1920s.