Why Functional Programming?

Learn about the need for functional programming and its key attributes.

Somehow, functional programming feels like a relatively new concept. This is strange, considering it slightly predates object-oriented programming (OOP). This might be the case OOP largely won out over functional programming. OOP has been the reigning programming model for several decades now. Outside of the academic world, it’s often the one way all code is written.

Managing complex applications

OOP seems old, familiar, and trustworthy. Functional programming is exotic and unknown. At the same time, the ideas behind functional programming are well-suited to our world. It offers a new way to manage the growing complexity of applications. Yes, OOP promised this as well, but most of us have experienced first-hand that OOP only partly fulfilled its promise. Spaghetti codeThis code refers to a messy code that is hard to understand and sometimes makes it very complex to understand because of its non-structural implementation. is still very real.

Parallelism

Functional programming is also keen on helping us deal with the parallelism with which other models struggle. This was fine decades ago but is troublesome in an age where every computer, and practically every smartphone, has a multicore CPU.

Functional features in object-oriented languages

Another reason functional programming may feel fresh and new is that more and more object-oriented languages are adding functional features, such as:

  • Java 8 gave us streams.
  • Java 14 brings records.
  • Other languages have taken a pragmatic approach and let us pick and mix our styles of coding. Scala has been doing this for a long time. Kotlin is a more recent example.

Functional programming and object-oriented programming

One final reason functional programming may seem new is that it’s rarely employed regularly. You’ve probably read about its potential and how it will change the way we think about code, but back in the real world, recruiters only ask about our experience with OOP.

Furthermore, the languages a company uses are often better suited for writing code in OOP, frustrating our attempts to write beautiful functional code. For example, consider Java and Python. Java is not only very verbose, but it also lacks support for functions as first-class citizensIn any programming language, functions are said to be first-class citizens if they can be treated like any other variable. For instance, they can be passed as an argument to other functions, can be returned by another function, and can be assigned as a value to a variable.. This alone makes writing functional code, at best, a laborious chore. Python’s functions are first-class citizens, and ceremonyA programming language is said to have a high ceremony if it involves a lot of boilerplate code, such as type definitions and wrappers that are required before any program can be written. C++ and Java are examples of high ceremony languages. is minimal. Even though we can write Python in a functional style, it wasn’t created as a (primarily) functional language.

Note: We can write beautiful applications with object-oriented programming and create unmaintainable programs with functional programming. Both styles have their own advantages and disadvantages. However, functional programming offers several beneficial qualities to make it a valid choice when starting work on a new application.

This course is based on two of the most popular languages. The first is TypeScript. The second, JavaScript, is ubiquitous in the frontend and growing in the backend.