What is functional programming and why it matters for your business?

Since functional programming evolved from lambda calculus and has its roots in academia, it was initially discussed in scholarly contexts. It’s no longer the case. Even though significant technologies associated with functional programming (such as Lisp or Scala) were created at universities — FP is making its way to the general “software development discourse,” and some might say that it’s taking it by storm. 

Despite the rising interest, however, not many articles on the web seem to tackle the benefits of functional programming for business. Let’s face it: hacking a new technology in spare time is great, but there’s always a practical side to business when it comes to trying out new things and having a good reason for that. And that’s precisely what we’re about to cover in this piece. 

Here’s what functional programming is, and why does it matter for your business. 

What is functional programming in the first place?

Functional programming (FP) is a programming paradigm, a certain way of thinking about software development that’s based on a few defining principles. In the case of FP, these key principles are as follows:

  1. Binding everything in pure mathematical functions. The purpose is to look for simple, repeatable actions that can be abstracted out into a function and then built upon to create more complex features.
  2. Immutable, unchangeable data — which means that you should rather create new data structures, not altering the ones that are already in place. For example, if you want to modify data in an array, you need to add a new array with the updated value instead of making changes to the “original” one. 
  3. Declarative code. The main focus here is on what to solve, rather than how to do it. 
  4. Statelessness. Functional programs should perform each and every task as it was for the very first time, without any knowledge of what happened (or not) earlier in their execution. 
  5. Recursion. There is no “for” or “while” loop in functional languages, iteration is implemented through recursion. Basically, recursive functions repeatedly call themselves, until the base case is reached. 

Functional programming vs OOP (Object Oriented Programming)

Speaking of programming paradigms, you might already be familiar with another one that’s still more popular: object-oriented programming (OOP). This doesn’t mean, however, that FP is not gaining any traction. Both functional programming and object-oriented programming are unique in their own ways. 

Here’s functional programming vs OOP at a glance to help you grasp the differences:

XFunctional programmingObject-oriented programming
DataImmutableMutable
Programming modelDeclarative Imperative
FocusWhat you’re doingHow you’re doing
Parallel programmingSupports parallel programmingNot suitable for parallel programming
Side effectsIts functions have no side effectsIts methods can produce side effects 
IterationRecursion“Loop” concept
Application stateFlows through pure functionsIs usually shared and colocated with methods in objects 
Key elements of the codeVariables and functions are the main elements of the codeObjects and methods are the key elements

What about programming languages, then?  

Pure functional programming languages, such as Haskell, are specially designed to serve this particular paradigm and accept only pure functions. Interestingly, you don’t need to use a pure functional programming language to bring FP principles to your code. 

There are a few languages that still make it easy to write “pure programs”, such as Scala, Clojure or OCaml.  More popular programming languages like JavaScript or Python can also support FP one way or the other – either natively or with the right library.

At Scalac, we’re big advocates of functional programming and, which shouldn’t come as a surprise, we mainly use Scala for this purpose.  There are at least a few good reasons for that:

  • The language is extremely versatile and offers advanced features, clean code, and both functional and object-oriented programming in an open-source, practical package that leverages Java’s environment. 
  • Speaking of — Scala has emerged as one of the most powerful Java alternatives. Actually, one of the reasons why Scala was created in the first place was to address various concerns developers had with Java. Nowadays, Scala provides interoperability and compatibility with Java, allowing the developers to keep their Java libraries, and leverage the advantages of JVM. 
  • When comparing it to Python, on the other hand, Scala’s maintenance is simply much faster. Despite providing the fluency and flexibility of a dynamic language like Python, it’s still a strongly statically typed language. The performance also tends to be much more efficient, especially in a multi-threaded environment.  
  • Because of its functional aspects and flexibility, Scala is also useful for expressive code and parallelism. Basically, with a functional approach and no mutation, there are no race conditions and parallelism gets a lot more straightforward. Then, lambda expressions are also helpful when communicating some aspects of parallelism. 

But, the question remains:

Why should you use functional programming (and Scala, for that matter)?

For some reason, this programming paradigm still seems complex for many. When taking a closer look at the benefits of functional programming and languages associated with it, you might have a different impression. 

To start with, adopting functional programming helps you break down every application into smaller, simpler pieces that are both more reliable and easier to understand. It’s mostly because functional code tends to be more concise, predictable, and easier to test. How come? 

  • Since pure functions don’t change any states and depend only on the input given, they are much easier to grasp
  • When there’s less code, there are also fewer bugs — not to mention that actual testing and debugging gets much easier with immutable data and pure functions that take only arguments and produce output. 
  • With the outputs depending only on the arguments passed to the function, the software can also behave more “predictably”
  • FP adopts Lazy Evaluation which avoids repeated evaluation (basically, the value is evaluated and stored only when it is needed) and supports other Lazy Functional Constructs like Lazy Lists, Lazy Maps, etc. 
  • Functional programming also means efficient parallel coding — there’s no mutable state and no state-change issues, which supports easy reusability and testability. 
  • Speaking of efficiency, functional programs consist of independent units that can run concurrently and can be more efficient as a result. 

Since Scala supports functional programming, these benefits apply to it as well. In fact, the combination of features in Scala makes it possible to write programs that are concise, elegant, and much easier to debug & maintain. 

As a result, increasingly more companies switch to both functional programming and Scala, including well-known tech giants like Twitter or LinkedIn. Interestingly, Scala also made it to the top 10 languages that developers want to learn these days. 

The rising interest from both companies and developers are contributing to the recent growth of functional programming and the adoption of Scala as the main language for many applications — also in a business setting. 

What do functional programming & Scala mean for your business, though?

There’s no doubt that knowing the principles of functional programming can broaden one’s horizons and introduce new ways of thinking about software development. But what’s in it for the companies? 

To start with, code quality. When it comes to functional programming — very often, you can do more with less code. It’s much more concise, which essentially means fewer bugs, and shorter time (and/or fewer people) to actually write it. Plus, it’s a lot easier to grasp what the code does, explain it, and even onboard new team members who can almost immediately join the project and start working on it. In the process, Time to Market often gets shorter. 

What’s also worth mentioning is that the interest in functional programming and languages that bring its principles to life stems from being tired of limitations posed by other programming paradigms and technologies. As already mentioned, Scala as a modern language has plenty of useful features that you won’t find in Python and Java. Even implementing it can be a big savings cost of the bottom line. 

What’s more, there are already some business cases that both functional programming and Scala have been applied to successfully. Health care, accounting, banking, advertising — are just a few exemplary industries.

For the time being, functional programming seems to work best with apps aimed at concurrency or parallelism, carrying out mathematical computation, and whenever there are many different operations performed on the same data set. Scala is a good fit if you have a lot of data or complex data structures and algorithms, but FP languages are also often used for artificial intelligence applications like machine learning, language processing, or modelling of speech and vision. Pretty impressive, right?

With the rising interest and so many benefits of functional programming, how come it’s not yet as widespread as it should be? 

At the end of the day, businesses rather choose the technology based on the skills of their team or the availability of developers, who are more likely to represent more traditional approaches to software development. That’s precisely why it matters not only to educate developers about FP but also give them tools to apply it in practice. 

For now, “the movement” is all bottom-up: it’s starting from developers who are tired of being limited by other programming languages, become interested in functional programming, and then teach their colleagues about it. 

As these developers start creating libraries and frameworks that solve specific business problems across multiple areas (such as backend development, analytics, distributed development) with the use of functional programming — eventually decision-makers will also get excited about FP. And, the more companies are interested in functional programming, the more developers skilled at it they want to hire. It’s a chain reaction from there. 

To facilitate the shift to functional programming, drop some of the jargon around FP and lower the barriers to entry, there are initiatives and projects like ZIO — a library for asynchronous and concurrent programming based on pure functional programming. Taking advantage of it is said to help in solving common business problems, and ensuring higher success rates of projects. This, in turn, brings more attention to functional programming, in the business world as well. 

What’s also great about ZIO is that it’s inclusive for all sorts of developers. It’s still fairly new, but it’s expected to be a great venture in the long run, mostly due to all the open-source support it gets. It might be difficult to take advantage of ZIO when developing enterprise-level software just yet, but more and more companies are already testing it in production for smaller projects. And that’s only one of the reasons why the future of functional programming definitely is bright. 

Dig into functional programming yourself 

Increasingly more companies are prepared to train development teams on how to use FP and solve business problems with functional programming, including Scalac

Switching to functional programming can be done whenever there’s a new module to implement and thus, can be done gradually. Start small, and see how big of a difference the main aspects of functional programming can make to your business. As per usual, we’re here to help

Author

Łukasz Kuczera

I wrote the first computer program when I was 8 and founded the first company when I was 16. Since then, I'm looking for opportunities to improve the world around me. I'm a peoples person, and I love to lead and inspire. I couldn't find a "company that I always wanted to work for," so I decided to create my workplace where I can share my passion with likeminded individuals. I have been wearing different hats throughout my career and founded several projects and companies. I worked as a System Administrator, Software Engineer, and Architect I held the role of VP of Engineering and CEO. I founded ISP company, gamification startup, Venture Fund, Gamedev studio, and specialized software development company.

Latest Blogposts

13.11.2020 / By Anna Berkolec

How to achieve your goals by creating good habits instead of setting milestones

Did you know that about 40% of what we do every day we do automatically? Almost half of our life is taken up by habits that we've formed over our lifetime. People are simple creatures, and if something works, why not stick with it?

28.10.2020 / By Maciej Greń

Tubi x Scala: Why it works?

If you want to succeed in a World of ever-changing technology, you always need to be a step ahead of your competitors. Constantly pushing the boundaries is crucial if your business is to provide a flawless customer experience, and grow. Today, we’re going to show you the perfect example of a company that wasn’t scared of scaling up machine experimentation with Scala. And let us just take a sneak peek at that in one sentence: “I love working with Scala” | Alexandros Bantis, backend Scala Developer at Tubi The outcome is rather impressive, so read on to find out more about it!

01.10.2020 / By Daria Karasek

Do Scala with Scalac – 7 success stories to follow

From challenges to achieving goals - building a complex solution takes time and effort in order to seize all opportunities and deliver a high-quality product. Thinking about all the aspects you have to handle when developing software or making changes to existing ones can be a little overwhelming. Especially when a solution that used to work doesn’t fit your needs anymore and bottlenecks give you sleepless nights. Picking the right partner to help you manage this is a hard nut to crack. Maybe it’s high time to ask other companies about their own experience and recommendations?

Need a successful project?

Estimate project