OOP vs Functional Programming
Object-oriented code keeps data and actions together in objects. Those objects change over time. Functional code passes data through small functions. They make new values and change nothing.
Object-Oriented Programming (OOP)
Code built from objects. Each object holds its own data and actions.
Object-oriented programming builds programs out of objects. Each object holds its own data and the actions that use it. You write a class once, like a plan for a dog, then make many dogs from it. Objects talk by calling each other's methods. Four big ideas sit at its core: hiding data, sharing code, swapping parts and keeping things simple. Java, C# and Python all use it.
Functional Programming
Code that hands back new values from small functions. Nothing changes in place.
Functional programming builds programs out of small functions. Each takes inputs and gives back outputs. A function in this style does not change anything outside itself. Data is not edited in place; you make a new copy with the change. Functions can be passed around like any other value. Haskell is built on it, and JavaScript and Python let you use it.
In one line
- Object-Oriented Programming (OOP)
- Code built from objects. Each object holds its own data and actions.
- Functional Programming
- Code that hands back new values from small functions. Nothing changes in place.