What is Functional Programming?
Functional programming can be viewed as starting from lambda calculus developed by American mathematician Alonzo Church in the 1930s.
in theoretical computer science and mathematical logic, a formal system that abstracts function definition and application
and inductive functions.
Unlike imperative programming languages like Fortran and Algol that emphasize state changes, functional programming emphasizes function application.
That is, it refers to programming that treats data processing as calculation of mathematical functions and excludes state and mutable data. Since there’s no need to specify execution order, it’s also called a non-procedural language.
Functional programming languages include Haskell, Scheme, etc.
What is Object-Oriented Programming?
Its beginning can be found in SIMULA, a simulation language that was popular in 1960.
and objects that receive processing requests process them using functionality within themselves.
Object-Oriented Programming, which represents the real world, has characteristics of encapsulation, inheritance, and polymorphism, and is often compared with Procedure-Oriented Programming.
While difficulty in reuse and maintenance increases rapidly as code lines increase, Object-Oriented Programming is relatively easier for extension and maintenance due to module reuse, etc.
Object-Oriented Programming languages include Java, Smalltalk, etc.
How Can We Compare Functional and Object-Oriented?
From a language perspective, we can think about first-class objects (or first-class citizens, first-class entities).
In functional languages, functions themselves become first-class objects, but in object-oriented languages, classes (or objects, Object) become first-class objects.
Quoting Wikipedia on conditions for first-class objects:
- Can be stored in variables or data structures
- Can be passed as parameters (to subroutines)
- Can be used as return values (of subroutines)
- Can be uniquely identified regardless of names used in assignment
If Object-Oriented Programming emerged to overcome disadvantages of Procedure-Oriented Programming, Functional Programming emerged to overcome disadvantages of Object-Oriented Programming.
For example, Object-Oriented can view programs as collections of interacting objects, but Functional enables thinking of them as sequences of function values without state values.