Jorge Castro
1 min readJul 31, 2019

It is just a code but it’s not the whole point of the conversation. For this case, we are not talking about code but paradigm. Now, you can say “your code is not functional programming”, AND THAT’S MY WHOLE POINT. What is functional programming and what is not?.

But lets me talk about your example:

Let’s say our project is huge, 100k lines of code and lots of moving parts here and there.

It is your code

apple = fruits.find(f => ‘apple’ === f.name);
if (apple) applePrice = apple.price;

Now, let’s say that

apple = fruits.find(f => ‘apple’ === f.name);

is found somewhere, maybe in a different file. Why?. Because we want to reuse it.

And in another part of the code, we found the next line:

if (apple) applePrice = apple.price;

Question: If we only have access to this code, what it does? Is Apple a variable, a class, a function or what?

Now, let’s say the same line written in OOP

class AppleService {
function find(object) {
// ….
}
}

if(AppleService.find(apple)) {
applePrice=apple.price
}

Long but it is almost self-explanatory. We find an object apple (using apple service), if the find it, then we store the price. We won’t need to peek at the definition of “apple”. The object just values while the service class is a collection of function. What’s the goal? What if the function fails?. Simple. We go to AppleService, find the function, edit and that’s it. We won’t need to hunt for the code.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

The author has closed discussion for this story. Learn more.