What is Object-Oriented Programming? What is Functional Programming?

Object-Oriented Programming(OOP) and Functional Programming (FP) are programming paradigms that allow us to organize our code in a specific manner.

But what's the difference between them?

What is Object-Oriented Programming?

Object-Oriented Programming(OOP) let's us organize code into units. For instance, if we are building a robot, we might have a head component, an arm component, a leg component, etc.

In our case, these components would be represented by objects, containing information such as state/attributes and also methods to alter this information.

In the above example, we created an object with name and weapon as attributes and a method.

Older programming languages were focused more on OOP but new languages seem to trend more towards functional programming.

What is functional programming?

Functional programming basically says, “let's create some functions that accept some data, and then I'll do some logic on it, and then I'll return some new data or information to you.”

The goal of functional programming is to make reusable functions that can create and act on some data that they are presented with.

In the above example, we have a user with some state and a re-usable function that lets us alter that user data. In this particular example, we have a user whose account is not active. The function takes in a user, sees that this user is in fact a user, and then activates their account.