patpitchaya - Fotolia


Scala: Lightweight functional programming for Java

Scala provides a lightweight code option for Java development, but there could be a steep learning curve. Learn a little about Scala and if it's worth adopting.

Languages based in Java often involve verbose syntax and domain-specific languages for testing, parsing and numerical compute processes. These things can be the bane of developers, because the piles of repetitive code require developers to spend extra time combing through it to find errors.

As a general-purpose programming language, Scala can help alleviate these issues by combining both object-oriented and Functional styles. To mitigate syntax complexities, Scala also fuses imperative programming with functional programming and can advantageously use its access to a huge ecosystem of Java libraries.

This article examines Scala's Java versatility and interoperability, the Scala tooling and runtime features that help ensure reliable performance, and some of the challenges developers should watch out for when they use this language.

What is Scala?

Scala attracted wide attention from developers in 2015 due to its effectiveness with general-purpose cluster computing. Today, it's found in many Java virtual machine (JVM) systems, where developers use Scala to eliminate the need for redundant type information. Because programmers don't have to specify a type, they also don't have to repeat it.

Scala shares a common runtime platform with Java, so it can execute Java code. Using the JVM and JavaScript runtimes, developers can build high-performance systems with easy access to the rest of the Java library ecosystem. Because the JVM is deeply embedded in enterprise code, Scala offers a concise shortcut that guarantees diverse functionality and granular control.

Developers can also rely on Scala to more effectively express general programming patterns. By reducing the number of lines, programmers can write type-safe code in an immutable manner, making it easy to apply concurrency and to synchronize processing.

The power of objects

In pure object-oriented programming (OOP) environments, every value is an object. As a result, types and behaviors of objects are described by classes, subclasses and traits to designate inheritance. These concepts enable programmers to eliminate redundant code and extend the use of existing classes.

Scala treats functions like first-class objects. Programmers can compose with relatively guaranteed type safety. Scala's lightweight syntax is perfect for defining anonymous functions and nesting. Scala's pattern-matching ability also makes it possible to incorporate functions within class definitions.

Java developers can quickly become productive in Scala if they have an existing knowledge of OOP, and they can achieve greater flexibility because they can define data types that have either functional or OOP-based attributes.

Challenges of working with Scala

Some of the difficulties associated with Scala include complex build tools, a lack of support for advanced integrated development environment language features and project publishing issues. Other criticisms aim at Scala's generally limited tooling and difficulties working with complex language features in the codebase.

Managing dependency versions can also be a challenge in Scala. It's not unusual for a language to cause headaches for developers when it comes to dependency management, but that challenge is particularly prevalent in Scala due to the sheer number of Scala versions and upgrades. New Scala releases often mark a significant shift that requires massive developer retraining and codebase migrations.

Developers new to Scala should seek out the support of experienced contributors to help minimize the learning curve. While Scala still exists in a relatively fragmented, tribal ecosystem, it's hard to say where Scala is heading in terms of adoption. However, with the right support, Scala functional programming can be a major asset.

Dig Deeper on Application development and design

Software Quality
Cloud Computing