Why Functional Programming matters?

Fatih Nayebi
Swift Functional Programming
3 min readMay 3, 2016

Software solutions are becoming complex and it is necessary to structure them very well for the future maintenance and extension. Software engineers try to modularize software solutions to smaller pieces and abstract away complexities in different pieces and layers.

Dividing the code to smaller pieces makes it possible to tackle each problem individually. This approach improves the collaboration because different engineers can take responsibility on different pieces. Also they can work on specific parts of software without being concerned about the other parts.

Dividing software solutions to smaller pieces is not the biggest challenge in the most of projects and programming languages. For instance, in Object-Oriented programming software solutions are divided to smaller pieces such as packages, classes, interfaces and methods. Engineers tend to divide the software to these building blocks by domains, logic and layers. Classes are recipes to create instances and objects. As the name suggests the most important building blocks in Object-Oriented programming are Objects. Engineers deal with objects and the role and responsibility of them should be clear and understandable.

In Object-Oriented programming, connecting the building blocks to each other is not as easy as dividing them.

Connection between different objects may propose the strong coupling between them. Coupling is the biggest source of complexity in object-oriented programing. A change in a module or a class could force to change all coupled modules and classes. Also a particular module or class might be harder to reuse and test because of coupled modules or classes.

Software engineers try to loosen coupling by structuring the software very well and applying different principles and design patterns. For instance, SOLID (Single Responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency Inversion) Principles when they applied together properly tend to make software easy to maintain and extend.

Even though it is possible to decrease the coupling and simplify software structures, managing the memory, referencing to instances and testing of different objects remains difficult because in object-oriented programming objects are open to change and mutation.

In object-oriented programming objects are open to change and mutation.

In functional programming, pure functions are the most important building blocks. Pure functions do not rely on data outside themselves and they do not change data that exists outside them. Pure functions are easy to test because they will always provide the same results.

Pure functions can be executed on different threads or cores without any mechanisms to handle multithreading and multiprocessing. This is a very important benefit of functional programming over object-oriented programming since multi-core programming mechanisms are very complex to handle in object-oriented programming. Also, programming for multi-core computers is becoming more important day by day because hardware engineers have finally hit the speed limit of light. Computer clocks will not be getting faster in the near future so to have more cycles per seconds, hardware engineers are adding more processors into chips. There seems no end to how many processors we will have in our computers. Higher number of processors to be used for a program means a more complex multi-threading and multi-core mechanism to handle.

Functional programming eliminates the need for a complex multi-core programming mechanism and because pure functions are not dependent to any instances or data outside of themselves it is easy to change them without changing other parts.

Functional programming eliminates the need for a complex multi-core programming mechanism

--

--

Fatih Nayebi
Swift Functional Programming

Data Scientist, Author of Swift Functional Programming Book, Lecturer at McGill University