Function — building block for functional programming

One Thing Scala — One: Why do we need functions?

Learn
2 min readJun 12, 2021

This is to talk about why we need functions in the first place given that we already have object oriented programming?

Function is an abstraction of a functionality. It is a “do something” that can take any number of parameters and can return a result or not actually return a result but perform the actions that it was defined to do.

This is what a method does within a class. Function and method are exactly the same except that function does not need the backing of a class to define itself.

That is all a function is. Just a definition of a functionality without the class.

Wouldn’t it be easier if we could just define functions when we please instead of having to also decide which class we should place this function in. Should we add this function on this class or that class or should we create a brand new class to start holding this function and more such functions that we might think of in the future? These are all problems you have to deal with because object oriented programming treats class as a very fundamental concept and does not have the provision to just define a function when you need to as part of your business problem.

Functional programming is a strong paradigm with many advantages like the ability to be executed in parallel, which is an advantage that becomes even more relevant as computers begin to support multiple processors.

Without getting into too much detail, let us just say that functional programming is a really good thing and the fundamental building block for functional programming is a function, and that is the reason we need functions.

--

--

Learn
Learn

Written by Learn

On a continuing learning journey..

No responses yet