OOP vs Functional Programming
What is OOP?
OOP stands for Object Oriented Programming and is a way of writing code to solve problems in a way that is not language specific. OOP primarily focuses on using objects containing data and methods to solve problems, the benefit of this is that it’s easier to manage and make changes to code.
A way of writing code to solve problems, not language specific
Uses objects that contain data and has methods
Contains modules and is flexible
Easier to manage and make changes to code
- Encapsulation
- limiting what data is visible/accessible by other objects
- binding data and methods together in a class
- restricts access to data inside objects, only the methods inside that object can make changes
- Abstraction
- showing essential features of an application and hiding the details
- limits what is displayed to users/developers
- Inheritance
- reuse code from other classes
- access and use functions written in another class
- Polymorphism
- Create functions, same name, different arguments
- Redefine functions
What is Functional Programming?
Functional programming is a way of writing code to solve problems through using a series of functions that execute. Using functional programming can make code faster as it is only taking an input and processing an output however you do lose some flexibility as a result.
A way of writing code consisting of functions which execute
Input -> Function -> Output
Can be quicker than OOP, less code needs to be written
Programming without variable assignment
Implements immutability
-
- Functions can’t change inputs
- execute a function on that input and produce an output
- Can’t use loops because of incrementer, cant use counters
- Loose some flexibility but gain speed