Torbz - Fotolia

Tip

3 ways to implement a functional programming architecture

Functional programming, which came about as a highly theoretical, mathematical way to build software, has a place in APIs and other components of applications.

Functional programming languages work on an entirely different level than widely understood procedural and object-oriented programming techniques. The functional language approach is to create mathematical operations and evaluate those operations on a set of code.

While functional programming falls outside of the mainstream code languages, developers and architects interested in it should consider three ways to implement it: as part of a functional architecture, as part of an isolated or independent architecture, or as part of a hybrid programming model.

Functional programming architecture

Fundamentally, a pure functional programming language should not retain state and is more like a math expression than a procedural program. This architecture works for compiler construction or, perhaps, for APIs. A program to shorten and forward a URL, for example, might better fit a pure functional language than other, more common approaches.

List processing, or LISP, is an impure functional language in that it can mix in traditional procedural programming along with the functional approach by using states and control flow.

Unfortunately, few applications tend to fit a pure functional approach, and few programmers want to program in a mixed language like LISP. Software architectures, however, allow for two other functional programming approaches that fit some projects.

A functional architecture in isolation

Distributed and decoupled architectures can run services based on functional code. For example, the front end of an application may be written with HTML, CSS and JavaScript, but the back end can be separated from the front end by TCP/IP protocols. In a 2003 article titled "Beating the Averages,"  Paul Graham, co-creator of Via-Web, realized the following:

Back in 1995, we knew something that I don't think our competitors understood, and few understand even now: When you're writing software that only has to run on your own servers, you can use any language you want.

Teams can implement APIs in functional programming languages, such as LISP, Haskell and Clojure. Those teams can also use containerization to mitigate the risk of using these unfamiliar languages within the wider software architecture. For instance, tools like Docker and Kubernetes can manage that risk: Docker containerizes the code to make it compatible with other code, and Kubernetes ensures any related API scales.

How is functional programming a valuable skill?

Functional programming, even if it isn't in use for a wide array of development projects, can change your career. DevOps expert Gene Kim said that learning Clojure turned him into a developer. "For the last 20 years, I've self-identified primarily as an ops person ... but three years ago, I started self-identifying as a developer, and I think it's because of learning Clojure, the functional programming language. And I've never had so much fun programming," Kim said. Check out his thoughts on developer roles and responsibilities within the DevOps movement.

Hybrid functional architectures

Understandably, some architects and development teams may hesitate to let siloed teams run a functional programming language on their own. Luckily for these organizations, a third architecture option exists that runs on Microsoft's Visual Studio development tools and the Java virtual machine (JVM).

Languages like C# and Java contain functional programming capabilities. For example, both C# and Java support lambda expressions, which act as little snippets of functional code inside an application.

Alternatively, it is possible in Visual Studio to write code in F#, a functional language, and whittle it down to executable code. This means the F# code can exist alongside C# and Visual Basic .NET code within the same project. You can do similar things with Clojure and Java, because Java can run on a JVM. These methods allow modern programmers to write functional code, or at least snippets of it, in a language the entire team can support -- such as lambda functions in Java and C#.

Author's note: Credit to Jonathan Chaffer, who provided a comprehensive peer review of this article.

Next Steps

Meet some functional programming languages, including Kotlin, Clojure, Scala and Elixir. And check out the functional elements of Groovy and Go, too.

Explore the Venn diagram of microservices and functional programming. See the ways in which these concepts overlap and contrast.

Haskell vs. PureScript: The difference is complexity

Understanding Roc: Functional and separate from the runtime

Dig Deeper on Application development and design

Software Quality
Cloud Computing
TheServerSide.com
Close