Digital Transformation & Software Engineering Services
Functional Programming in Scala

Functional Programming in Scala

We are fully immersed in the digital economy. The passage of time in the digital economy is far faster than anyone could have ever imagined. This alternative rate of time means decisions on software platforms, tools, languages, and methodologies are very critical. Anything that can facilitate faster time to market, platform resilience, and universal expressiveness and capabilities conveys distinct advantages. Couple that with a renewed resurgence of functional programming has thrust Scala clearly into the forefront of software development languages.

Banner-Ad-for-Blog-page-1--Digital-ServicesFunctional programming is a programming paradigm with roots in lambda calculus and function abstraction which treats computation as the evaluation of mathematical functions. It avoids changing state and mutable data which avoids programming side effects while reinforcing stability and predictability.

Learning to think and program within the functional paradigm requires a change in the mind-set of the programmer who was groomed in imperative, procedural programming. Embracing that change is the key to benefiting from functional programming. Investing purely in functional programming is not necessarily an obvious decision for many firms. Their knowledge and resources all reside in procedural programming languages, like Java. Scala allows the procedural functional gap to be easily bridged.

Scala first appeared in 2003 out of Sweden with full support for functional programming and a very strong static type system all running on the Java virtual machine (JVM). That allows the Scala programmer to use their procedural knowledge of Java while still employing and incorporating all of the latest features of Scala. Companies do not have to throw away their significant investments in Java and the JVM. Applications and modules can be created using both Java and Scala simultaneously until the full transformation to functional programming is complete.

Scala brings a few other key advantages. IT handles concurrency quite well through ‘actors’, functions are first-class citizens with the same rights as objects, closures, and monads. Another interesting aspect of Scala is the terse, compact yet expressive nature of the language. The code below shows a striking example comparing a Java class with an equivalent Scala class.

Figure 1 – Example Java Class

code2
Figure 2 – Equivalent Scala code of Java code from Figure 1
Less equivalent code translate into faster development time, more readable code, less cost to develop and maintain, and therefore, quicker time to market.  In today’s digital economy, first to market drives market acceptance and dominance.  Twitter was first to market and is therefore the leader in its segment.

About the Author

Dharmendra Kapadia Dharmendra Kapadia
Dharmendra Kapadia is the Senior Director of Solutioning for Ness Digital Engineering with 20+ years of experience as a software developer, enterprise architect, and technology advisor. He has a keen interest in functional programming languages, architecture, Big Data, and analytics, and how they can help businesses thrive in today’s digital economy.

Comments are closed.